-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: submitForm returns a resolved promise even when validation failed #3280
Comments
Duplicate of #1580 |
This is my workaround. Instead of using catch(), use then() and check for
Note that it might not be accurate in all scenarios. A proper fix would be needed. Or wait for v3 formikProps.getState().isValid. |
@olignyf the user could technically change the form during submit (unless you prevent this) if you use an async request, cause it to be valid or invalid even though the submission was the opposite, and the check above wouldn't work in v3. The validation result would have to be passed to onSubmit's promise to be accurate. The check could also not work in v2 if validation was not completed by the time the user submitted (e.g. async validation) |
@johnrom thanks for your reply. How come you think that
In my code I used the .then() async promise. Are you really saying that then() could fire while the validation have not ran yet? |
https://github.com/formium/formik/blob/903c1101240632c84fa36c8991ea9fd03b25f1cf/packages/formik/src/Formik.tsx#L785
Document says
submitForm
return a promise, which will reject when validation failed. But due to the line of code I mentioned, It wont throw when validation failed.Wish this bug fixed as soon as possible.
The text was updated successfully, but these errors were encountered: