Formik: v2 - submitForm does not reject promise when validation fails

Created on 24 Oct 2019  路  7Comments  路  Source: formium/formik

馃悰 Bug report

Current Behavior

The submitForm promise resolves even when there is a validation error via validationSchema or the validate function.
Example:

submitForm().then(data => {
    console.log('I should not resolve when validation fails');
})
.catch(err => {
       // Desired & expected behavior 
      console.log('If validation fails, i should log')
});

Expected behavior

If the validation fails, submitForm should throw errors

Reproducible example

Steps:

Suggested solution(s)

throw validation errors

Your environment

| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 2.0.1.rc-13
| React | 16.11.0
| TypeScript | NA
| Browser | Chrome
| npm/Yarn | yarn 1.16.0
| Operating System | Mac OS 10.13.6

Most helpful comment

@jaredpalmer still reproduced in 2.1.4
the fix seems to have been reverted with issue #1198 pr #2104
https://github.com/jaredpalmer/formik/pull/2104/commits/9ee2afe39ebdfb26ac95af632e470a7b9d919fba#diff-13cb4898b838c74f25fbdd7bb44a139fR768

All 7 comments

This is affecting my use of both Formik 1.x and 2.x as well. On smaller, isolated forms it can be managed by the developer, but for larger forms, or multiple forms that depend on the validation success / failure of other forms, it can result in a fair bit of development pain. A fix for this would be most appreciated! 馃憤

Fixed in rc.14

Fixed in rc.14

I'm still experiencing the error, in v2.0.1 and also rc.14/15. With a quick check on https://codesandbox.io/s/silly-kalam-fdq0x provided by @jsilvax it seems the bug is still present.

Fixed in rc.14

@jaredpalmer

This is still an issue in rc.14 & rc.15 & v2.0.3. You can still see the issue in the latest code in master.

The issue is this line which returns rather than throw combinedErrors:
https://github.com/jaredpalmer/formik/blob/49254b846e332440fb55357dac478cf26bc17631/src/Formik.tsx#L727

This open PR will fix the issue:
https://github.com/jaredpalmer/formik/pull/1843/commits/6daef57a907e34e9c7f3a845453c116cc6c9a9bd

It seems like this issue is still present in 2.0.3 -- getting a fix for this merged would be a huge help! Please let me know if there's anything I can do to assist in this endeavor.

Related PR: #1843

@jaredpalmer still reproduced in 2.1.4
the fix seems to have been reverted with issue #1198 pr #2104
https://github.com/jaredpalmer/formik/pull/2104/commits/9ee2afe39ebdfb26ac95af632e470a7b9d919fba#diff-13cb4898b838c74f25fbdd7bb44a139fR768

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jordantrainor picture jordantrainor  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

sibelius picture sibelius  路  3Comments

najisawas picture najisawas  路  3Comments