🚀 Feature request
Current Behavior
When submitting a form today, formik’s handleSubmit will run manual validation and then touch all fields to show the validation errors to the user.
If you run manual validation this behavior is not there, you have to manually check the results of the validation and touch all fields using setNestedObjectValues
(basically mimic what handleSubmit does)
Desired Behavior
formik’s validate form should have a flag that lets the user have the exact same behavior as handleSubmit to avoid having to use setNestedObjectValues
every time you trigger manual validation.
Suggested Solution
Adding an optional setTouched?: boolean
parameter to validateForm
to do this behavior.
I’ll be willing to do a PR for this! Let me know if you agree with the approach or if this has been considered but there’s a reason not to add it. Thanks!
@CristianoYL I’ve found that there is, if you run
formik.setTouched(setNestedObjectValues(errors, true))
whereerrors
is the result offormik.validateForm()
you get all the fields touched…. the problem is that you have to do it manually, instead of having an option to do it withinvalidateForm
… this is the code I have, which is basically a copy of whathandleSubmit
inside formik does.The problem is that if you want to touch all the fields every time you run manual validation you have to do this code all the time