To submit a form in Formik, you need to somehow fire off the provided handleSubmit(e)
or submitForm
prop. When you call either of these methods, Formik will execute the following (pseudo code) each time:
initialValues
are required and should always be specified. See #445isSubmitting
to true
submitCount
+ 1isValidating
to true
validate
, and validationSchema
asynchronously and deeply merge resultsisValidating
to false
, set errors
, set isSubmitting
to false
isValidating
to false
, proceed to "Submission"onSubmit
or handleSubmit
)setSubmitting(false)
in your handler to finish the cycleIf isValidating
is false
and isSubmitting
is true
.
It is common practice to only show an input's errors in the UI if it has been visited (a.k.a "touched"). Before submitting a form, Formik touches all fields so that all errors that may have been hidden will now be visible.
Disable whatever is triggering submission if isSubmitting
is true
.
If isValidating
is true
and isSubmitting
is true
.
The latest Formik news, articles, and resources, sent to your inbox.