@valar1/formik-wizard-form
Advanced tools
Comparing version 3.0.5 to 3.0.6
@@ -910,37 +910,44 @@ 'use strict'; | ||
case 0: | ||
console.log('handleNext', formikBag); | ||
isValid = false; | ||
if (!validateOnNext) { | ||
_context2.next = 6; | ||
_context2.next = 8; | ||
break; | ||
} | ||
_context2.next = 4; | ||
_context2.next = 5; | ||
return formikBag.validateForm(); | ||
case 4: | ||
case 5: | ||
errors = _context2.sent; | ||
console.log('Errors', errors); | ||
isValid = Object.keys(errors).length === 0; | ||
case 6: | ||
case 8: | ||
console.log('isValid1', isValid); | ||
if (!((validateOnNext && isValid || !validateOnNext) && isFunction(beforeNext))) { | ||
_context2.next = 16; | ||
_context2.next = 20; | ||
break; | ||
} | ||
_context2.prev = 7; | ||
_context2.next = 10; | ||
console.log('Before Next Validation', isFunction(beforeNext)); | ||
_context2.prev = 11; | ||
_context2.next = 14; | ||
return beforeNext(formikBag.values, formikBag, currentStep); | ||
case 10: | ||
case 14: | ||
isValid = true; | ||
_context2.next = 16; | ||
_context2.next = 20; | ||
break; | ||
case 13: | ||
_context2.prev = 13; | ||
_context2.t0 = _context2["catch"](7); | ||
case 17: | ||
_context2.prev = 17; | ||
_context2.t0 = _context2["catch"](11); | ||
isValid = false; | ||
case 16: | ||
case 20: | ||
console.log('Isvalid2', isValid); | ||
if (isValid) { | ||
@@ -950,3 +957,3 @@ isLastStep ? formikBag.submitForm() : goToNext(); | ||
case 17: | ||
case 22: | ||
case "end": | ||
@@ -956,3 +963,3 @@ return _context2.stop(); | ||
} | ||
}, _callee2, null, [[7, 13]]); | ||
}, _callee2, null, [[11, 17]]); | ||
})); | ||
@@ -989,3 +996,4 @@ }, [goToNext, currentStep, beforeNext, isLastStep, validateOnNext]); | ||
_handlePrev = _useWizard.handlePrev, | ||
_handleNext = _useWizard.handleNext; | ||
handleNext = _useWizard.handleNext, | ||
goToNext = _useWizard.goToNext; | ||
@@ -1025,3 +1033,3 @@ var currentStep = steps[currentStepIndex]; | ||
}(), | ||
handleNext: _handleNext(formikBag), | ||
handleNext: handleNext(formikBag), | ||
isFirstStep: isFirstStep, | ||
@@ -1035,5 +1043,3 @@ isLastStep: isLastStep, | ||
currentStepIndex: currentStepIndex, | ||
handleNext: function handleNext() { | ||
return _handleNext(formikBag); | ||
} | ||
goToNext: goToNext | ||
})); | ||
@@ -1062,3 +1068,4 @@ } | ||
_handlePrev = _useWizard.handlePrev, | ||
_handleNext = _useWizard.handleNext; | ||
handleNext = _useWizard.handleNext, | ||
goToNext = _useWizard.goToNext; | ||
@@ -1099,3 +1106,3 @@ var currentStep = steps[currentStepIndex]; | ||
}(), | ||
handleNext: _handleNext(formik$1), | ||
handleNext: handleNext(formik$1), | ||
isFirstStep: isFirstStep, | ||
@@ -1108,5 +1115,3 @@ isLastStep: isLastStep, | ||
return React__default.createElement(StepComponent, Object.assign({}, formik$1, { | ||
handleNext: function handleNext() { | ||
return _handleNext(formik$1); | ||
}, | ||
goToNext: goToNext, | ||
currentStepIndex: currentStepIndex | ||
@@ -1113,0 +1118,0 @@ })); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("formik");function o(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function c(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}var u,s=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new S(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=w(a,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function h(){}function p(){}var v={};c(v,o,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(k([])));y&&y!==e&&r.call(y,o)&&(v=y);var m=p.prototype=f.prototype=Object.create(v);function x(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return h.prototype=p,c(m,"constructor",p),c(p,"constructor",h),h.displayName=c(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},x(g.prototype),c(g.prototype,i,(function(){return this})),t.AsyncIterator=g,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new g(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(m),c(m,a,"Generator"),c(m,o,(function(){return this})),c(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=k,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(u={exports:{}}),u.exports),l=function(t){return"function"==typeof t},f=function(t,r,n){var o=r.length,a=e.useState(t),c=a[0],u=a[1],f=0===c,h=0===c,p=c>=o-1,v=e.useCallback((function(){return u(Math.max(0,c-1))}),[u,c]),d=e.useCallback((function(){return u(Math.min(c+1,o-1))}),[u,c,o]),y=r[c],m=y.beforePrev,x=y.beforeNext,g=e.useCallback((function(t){return i(s.mark((function e(){var r;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!0,!l(m)){e.next=10;break}return e.prev=2,e.next=5,m(t.values,t,c);case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),r=!1;case 10:r&&v();case 11:case"end":return e.stop()}}),e,null,[[2,7]])})))}),[v,c,m]),w=e.useCallback((function(t){return i(s.mark((function e(){var r;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!1,!n){e.next=6;break}return e.next=4,t.validateForm();case 4:r=0===Object.keys(e.sent).length;case 6:if(!(n&&r||!n)||!l(x)){e.next=16;break}return e.prev=7,e.next=10,x(t.values,t,c);case 10:r=!0,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(7),r=!1;case 16:r&&(p?t.submitForm():d());case 17:case"end":return e.stop()}}),e,null,[[7,13]])})))}),[d,c,x,p,n]);return{currentStepIndex:c,isPrevDisabled:f,isFirstStep:h,isLastStep:p,goToPrev:v,goToNext:d,handlePrev:g,handleNext:w}},h=["activeStepIndex","validateOnNext","steps","children"],p=["activeStepIndex","validateOnNext","steps","children"];exports.FormikWizard=function(t){var e=t.activeStepIndex,o=void 0===e?0:e,u=t.validateOnNext,l=void 0===u||u,p=t.steps,v=t.children,d=c(t,h),y=f(o,p,l),m=y.currentStepIndex,x=y.isPrevDisabled,g=y.isFirstStep,w=y.isLastStep,b=y.handlePrev,L=y.handleNext,S=p[m],k=S.component;return r.createElement(n.Formik,Object.assign({},d,{validationSchema:S.validationSchema}),"function"==typeof v?function(t){var e,n={handlePrev:(e=i(s.mark((function e(){return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,b(t)();case 2:return e.next=4,t.validateForm();case 4:case"end":return e.stop()}}),e)}))),function(){return e.apply(this,arguments)}),handleNext:L(t),isFirstStep:g,isLastStep:w,currentStepIndex:m,isPrevDisabled:x,isNextDisabled:l&&!t.isValid||!1,renderComponent:function(){return r.createElement(k,Object.assign({},t,{currentStepIndex:m,handleNext:function(){return L(t)}}))}};return v(a({},t,n))}:v)},exports.useFormikWizard=function(t){var e,o=t.activeStepIndex,u=void 0===o?0:o,l=t.validateOnNext,h=void 0===l||l,v=t.steps,d=c(t,p),y=f(u,v,h),m=y.currentStepIndex,x=y.isPrevDisabled,g=y.isFirstStep,w=y.isLastStep,b=y.handlePrev,L=y.handleNext,S=v[m],k=S.component,O=n.useFormik(a({},d,{validationSchema:S.validationSchema}));return a({},O,{handlePrev:(e=i(s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,b(O)();case 2:return t.next=4,O.validateForm();case 4:case"end":return t.stop()}}),t)}))),function(){return e.apply(this,arguments)}),handleNext:L(O),isFirstStep:g,isLastStep:w,currentStepIndex:m,isPrevDisabled:x,isNextDisabled:h&&!O.isValid||!1,renderComponent:function(){return r.createElement(k,Object.assign({},O,{handleNext:function(){return L(O)},currentStepIndex:m}))}})}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("formik");function o(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function c(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}var u,s=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new S(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=w(a,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function h(){}function p(){}var d={};c(d,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(k([])));y&&y!==e&&r.call(y,o)&&(d=y);var g=p.prototype=f.prototype=Object.create(d);function m(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:N}}function N(){return{value:void 0,done:!0}}return h.prototype=p,c(g,"constructor",p),c(p,"constructor",h),h.displayName=c(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(x.prototype),c(x.prototype,i,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),c(g,a,"Generator"),c(g,o,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=k,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(u={exports:{}}),u.exports),l=function(t){return"function"==typeof t},f=function(t,r,n){var o=r.length,a=e.useState(t),c=a[0],u=a[1],f=0===c,h=0===c,p=c>=o-1,d=e.useCallback((function(){return u(Math.max(0,c-1))}),[u,c]),v=e.useCallback((function(){return u(Math.min(c+1,o-1))}),[u,c,o]),y=r[c],g=y.beforePrev,m=y.beforeNext,x=e.useCallback((function(t){return i(s.mark((function e(){var r;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!0,!l(g)){e.next=10;break}return e.prev=2,e.next=5,g(t.values,t,c);case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),r=!1;case 10:r&&d();case 11:case"end":return e.stop()}}),e,null,[[2,7]])})))}),[d,c,g]),w=e.useCallback((function(t){return i(s.mark((function e(){var r,o;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(console.log("handleNext",t),r=!1,!n){e.next=8;break}return e.next=5,t.validateForm();case 5:o=e.sent,console.log("Errors",o),r=0===Object.keys(o).length;case 8:if(console.log("isValid1",r),!(n&&r||!n)||!l(m)){e.next=20;break}return console.log("Before Next Validation",l(m)),e.prev=11,e.next=14,m(t.values,t,c);case 14:r=!0,e.next=20;break;case 17:e.prev=17,e.t0=e.catch(11),r=!1;case 20:console.log("Isvalid2",r),r&&(p?t.submitForm():v());case 22:case"end":return e.stop()}}),e,null,[[11,17]])})))}),[v,c,m,p,n]);return{currentStepIndex:c,isPrevDisabled:f,isFirstStep:h,isLastStep:p,goToPrev:d,goToNext:v,handlePrev:x,handleNext:w}},h=["activeStepIndex","validateOnNext","steps","children"],p=["activeStepIndex","validateOnNext","steps","children"];exports.FormikWizard=function(t){var e=t.activeStepIndex,o=void 0===e?0:e,u=t.validateOnNext,l=void 0===u||u,p=t.steps,d=t.children,v=c(t,h),y=f(o,p,l),g=y.currentStepIndex,m=y.isPrevDisabled,x=y.isFirstStep,w=y.isLastStep,b=y.handlePrev,L=y.handleNext,S=y.goToNext,k=p[g],N=k.component;return r.createElement(n.Formik,Object.assign({},v,{validationSchema:k.validationSchema}),"function"==typeof d?function(t){var e,n={handlePrev:(e=i(s.mark((function e(){return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,b(t)();case 2:return e.next=4,t.validateForm();case 4:case"end":return e.stop()}}),e)}))),function(){return e.apply(this,arguments)}),handleNext:L(t),isFirstStep:x,isLastStep:w,currentStepIndex:g,isPrevDisabled:m,isNextDisabled:l&&!t.isValid||!1,renderComponent:function(){return r.createElement(N,Object.assign({},t,{currentStepIndex:g,goToNext:S}))}};return d(a({},t,n))}:d)},exports.useFormikWizard=function(t){var e,o=t.activeStepIndex,u=void 0===o?0:o,l=t.validateOnNext,h=void 0===l||l,d=t.steps,v=c(t,p),y=f(u,d,h),g=y.currentStepIndex,m=y.isPrevDisabled,x=y.isFirstStep,w=y.isLastStep,b=y.handlePrev,L=y.handleNext,S=y.goToNext,k=d[g],N=k.component,E=n.useFormik(a({},v,{validationSchema:k.validationSchema}));return a({},E,{handlePrev:(e=i(s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,b(E)();case 2:return t.next=4,E.validateForm();case 4:case"end":return t.stop()}}),t)}))),function(){return e.apply(this,arguments)}),handleNext:L(E),isFirstStep:x,isLastStep:w,currentStepIndex:g,isPrevDisabled:m,isNextDisabled:h&&!E.isValid||!1,renderComponent:function(){return r.createElement(N,Object.assign({},E,{goToNext:S,currentStepIndex:g}))}})}; | ||
//# sourceMappingURL=formik-wizard-form.cjs.production.min.js.map |
@@ -903,37 +903,44 @@ import React, { useState, useCallback } from 'react'; | ||
case 0: | ||
console.log('handleNext', formikBag); | ||
isValid = false; | ||
if (!validateOnNext) { | ||
_context2.next = 6; | ||
_context2.next = 8; | ||
break; | ||
} | ||
_context2.next = 4; | ||
_context2.next = 5; | ||
return formikBag.validateForm(); | ||
case 4: | ||
case 5: | ||
errors = _context2.sent; | ||
console.log('Errors', errors); | ||
isValid = Object.keys(errors).length === 0; | ||
case 6: | ||
case 8: | ||
console.log('isValid1', isValid); | ||
if (!((validateOnNext && isValid || !validateOnNext) && isFunction(beforeNext))) { | ||
_context2.next = 16; | ||
_context2.next = 20; | ||
break; | ||
} | ||
_context2.prev = 7; | ||
_context2.next = 10; | ||
console.log('Before Next Validation', isFunction(beforeNext)); | ||
_context2.prev = 11; | ||
_context2.next = 14; | ||
return beforeNext(formikBag.values, formikBag, currentStep); | ||
case 10: | ||
case 14: | ||
isValid = true; | ||
_context2.next = 16; | ||
_context2.next = 20; | ||
break; | ||
case 13: | ||
_context2.prev = 13; | ||
_context2.t0 = _context2["catch"](7); | ||
case 17: | ||
_context2.prev = 17; | ||
_context2.t0 = _context2["catch"](11); | ||
isValid = false; | ||
case 16: | ||
case 20: | ||
console.log('Isvalid2', isValid); | ||
if (isValid) { | ||
@@ -943,3 +950,3 @@ isLastStep ? formikBag.submitForm() : goToNext(); | ||
case 17: | ||
case 22: | ||
case "end": | ||
@@ -949,3 +956,3 @@ return _context2.stop(); | ||
} | ||
}, _callee2, null, [[7, 13]]); | ||
}, _callee2, null, [[11, 17]]); | ||
})); | ||
@@ -982,3 +989,4 @@ }, [goToNext, currentStep, beforeNext, isLastStep, validateOnNext]); | ||
_handlePrev = _useWizard.handlePrev, | ||
_handleNext = _useWizard.handleNext; | ||
handleNext = _useWizard.handleNext, | ||
goToNext = _useWizard.goToNext; | ||
@@ -1018,3 +1026,3 @@ var currentStep = steps[currentStepIndex]; | ||
}(), | ||
handleNext: _handleNext(formikBag), | ||
handleNext: handleNext(formikBag), | ||
isFirstStep: isFirstStep, | ||
@@ -1028,5 +1036,3 @@ isLastStep: isLastStep, | ||
currentStepIndex: currentStepIndex, | ||
handleNext: function handleNext() { | ||
return _handleNext(formikBag); | ||
} | ||
goToNext: goToNext | ||
})); | ||
@@ -1055,3 +1061,4 @@ } | ||
_handlePrev = _useWizard.handlePrev, | ||
_handleNext = _useWizard.handleNext; | ||
handleNext = _useWizard.handleNext, | ||
goToNext = _useWizard.goToNext; | ||
@@ -1092,3 +1099,3 @@ var currentStep = steps[currentStepIndex]; | ||
}(), | ||
handleNext: _handleNext(formik), | ||
handleNext: handleNext(formik), | ||
isFirstStep: isFirstStep, | ||
@@ -1101,5 +1108,3 @@ isLastStep: isLastStep, | ||
return React.createElement(StepComponent, Object.assign({}, formik, { | ||
handleNext: function handleNext() { | ||
return _handleNext(formik); | ||
}, | ||
goToNext: goToNext, | ||
currentStepIndex: currentStepIndex | ||
@@ -1106,0 +1111,0 @@ })); |
@@ -13,3 +13,3 @@ /// <reference types="react" /> | ||
currentStepIndex: number; | ||
handleNext: () => void; | ||
goToNext: () => void; | ||
}>; | ||
@@ -16,0 +16,0 @@ }; |
{ | ||
"name": "@valar1/formik-wizard-form", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "Valari Fork - Create stepper forms over formik with ease", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
253500
2058