I have one page with multiple form. Each form is independent from other.
My question is how to handle all form submitting with one button??
I had the same requirement, you can extract the Formik and Form tags in common file and pass enableReinitialize={true} to your
Code snippet I used to handle this situation:
render() {
let currentStep = this.props.steps[this.state.currentStepIndex];
const CurrentStepComponent = currentStep.component;
return (<Formik
enableReinitialize={true}
initialValues={currentStep.initialValues}
validationSchema={currentStep.validationSchema}
onSubmit={(values, { setSubmitting }) => {
setSubmitting(true);
// Deal with current form-view values.
setSubmitting(false);
}}
>
{CurrentStepComponent && <CurrentStepComponent {...formik} />}
{
// Common submit button can be placed here.
}
</Formik>)
}
Hope this is helpful for you.
More info pls and/or code example
@edwinwong90 Nice job! How would you do validation and error handling with this?
@edwinwong90 thanks bro,
can you please do validation and error handling with this to use **Yup**
also can we update state on handleSubmit instead of onChange
I have the same question!
Updated code example
https://codesandbox.io/s/formik-multiple-form-in-one-submission-5qmt2
Closing due to long inactivity
Most helpful comment
@edwinwong90 thanks bro,
can you please do validation and error handling with this to use
**Yup**also can we update state on handleSubmit instead of onChange