formik icon indicating copy to clipboard operation
formik copied to clipboard

Manual trigger validation with validateForm does not display errors

Open damianchojna opened this issue 5 years ago • 6 comments

Current Behavior

After executing the validateForm method, I don't see any errors

Expected behavior

After executing the validateForm method, form errors should appear

Reproducible example

Click button "validate form" https://codesandbox.io/s/formik-validatefieldwithschema-6witd

example from: https://github.com/formium/formik/blob/master/examples/ValidateFieldWithSchema.js

damianchojna avatar Apr 16 '21 00:04 damianchojna

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

github-actions[bot] avatar May 17 '21 00:05 github-actions[bot]

I have same issue

blohamen avatar Jun 15 '21 14:06 blohamen

The default ErrorMessage component does not display errors until a user has "touched" the field, aka focused or un-focused the field. You can trigger this in code via setTouched() or setFieldTouched(fieldName, true). Calling submitForm will automatically set all fields touched.

johnrom avatar Jun 15 '21 14:06 johnrom

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

github-actions[bot] avatar Jul 16 '21 00:07 github-actions[bot]

Heya, This problem is related to #2345. I first of all thought it might be a bug because I expected the field to be touched when I manually call validateForm. I figured out that if you are using a multi-stage form then Formiik will have no real idea which fields to set as touched which makes sense as to why you have to call setTouched manually.

I suggest that something get added to the validation.md guide to alert users of this library that you will have to call setTouched manually on fields in this situation. I'll have a play to see if I can find a neat way to do it and then look to submit something to add this to the documentation.

chrisl-peopleplus avatar Oct 27 '22 11:10 chrisl-peopleplus

i have same issue, and because i do not add require validation(i used yup to validate)😭

empty916 avatar Feb 03 '23 01:02 empty916