jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34.02k stars 2.79k forks source link

Manual trigger validation with validateForm does not display errors #3151

Open damianchojna opened 3 years ago

damianchojna commented 3 years ago

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

github-actions[bot] commented 3 years ago

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

blohamen commented 3 years ago

I have same issue

johnrom commented 3 years ago

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.

github-actions[bot] commented 3 years ago

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

chrisl-peopleplus commented 2 years ago

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.

empty916 commented 1 year ago

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