I am trying to reset all errors in the form.
I tried using setErrors
and setStatus
, none of these are working. Errors in Formik state is not getting cleared.
setErrors({errors: {}})
and
setStatus({ errors: {}});
None of the above worked.
resetForm()
clears all errors, but the form values are also reset which I don't want. Any pointers to clear only the errors object?
While using setErrors , just pass the state of errors object you want. So to reset all errors, pass an empty object( {} ).
If you want to reset the selected value after the form is submitted, you need to provide a controlled value for the Select component. The Formik Field component provides the value in the props object, so you can use it.
We can reset the form by using the resetForm() method of formik. We can register it on the onClick event of the reset button.
While using setErrors
, just pass the state of errors
object you want. So to reset all errors, pass an empty object({}
).
setErrors({})
Codesandbox demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With