It's dead simple to submit a form in React Cool Form. All we need to do is to use an
<input type="submit"> or
<button type="submit"> element to fire the form's
onSubmit event. Moreover, we can also manually trigger a submission by the submit method of React Cool Form, which can help us overcome any kinds of design challenges easily.
This is the most common case that we submit a form in React Cool Form.
You might be curious about what happened after we clicked the submit button? Whenever a form is attempting to be submitted, React Cool Form will execute the following procedures:
- Touches all fields (for displaying errors)
- Runs all built-in, field-level, and form-level validations asynchronously and deeply merges the results.
- Once the validation is completed, sets
Are there any errors?
- Yes (Invalid): Runs the form's
onErrorhandler, jumps to "Post-submit"
- No (Valid): Proceeds to "Submission"
- Runs the form's
- Once the submission is completed, sets
👉🏻 See the Form State to learn more about it.
For some reasons (e.g. design requirement, auto-retry, etc.), we might need to trigger a submission manually. However, we can use the submit method to achieve it.