jaredpalmer / formik

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

Field-level validation run twice on submit #3853

Open quyle92 opened 1 year ago

quyle92 commented 1 year ago

Hi! I'm quite new to Formik and ran into an issue using field-level validation. Not sure if it's a bug or my fault.

Describe the bug: When using <Field validate={...} /> the validation gets called twice. I've tested with sample code in Formik doc but still have same issue. Also, another problem is the validateAsync triggers even when user fills in other fields. I've already tried FastField but it still re-renders when there are no direct updates to the 's relevant parts.

To Reproduce: A stripped down example of both cases can be found in this CodeSandbox.

Expected behavior: I would expect the validateAsync at validate prop should be called once per validation for performance reason. And the current field validation should not be triggered when there is no direct update happening.

Any help would be much appreciated! Thanks.

vennilamahalingam commented 1 year ago

Refer - https://codesandbox.io/s/formik-field-validate-not-working-when-using-hof-forked-whn8rj Validation triggers on blur, on change and on submit So you will have to set them false in the properties of Formik component. There's more on documentation about the same.

quyle92 commented 1 year ago

Thanks but how about the FastField issue? (i.e when there is onblur event triggered on email field, name field also gets validated, which I expect it should not).