In v2-rc.9, isValid becomes true when not all required fields are filled in
See original GitHub issue🐛 Bug report
For Formik v2.01-rc.9. isValid becomes true even if not all required fields are filled in.
Current Behavior
If you have a form with two fields and a Yup schema with both fields declared as required, once you type something valid on the first field, isValid
turns true, since the second field, empty but untouched, doesn’t get validated.
As I have the Submit button disabled when isValid
and dirty
are false, the user gets the wrong impression that the form is ready to submit. It eventually rejects the submission, and shows the error message, but the user is getting the wrong impression, after all, the interface enabled the submit button.
If you do start filling the second field, the submit button remains enabled but if you then backspace until the field is empty, the submit button gets disabled, as it should, and should have been the first time around as well.
Expected behavior
With v1, I used isInitialValid
which forced all fields to be changed, and thus validated, before isValid becomes true.
Currently, I am using initialErrors
with empty string on those required fields so, on the one hand, isValid
is false and the error text, being an empty string, is falsy and doesn’t distract the user with spurious error messages. (Actually, I get initialErrors
filled in based on what I get from analyzing what schema.describe
and checking for required fields)
Reproducible example
Sorry, codesandbox seems to be unable to fetch v2.0.1-rc.8 or 9. Most likely, I don’t know how to do it right, sorry.
Suggested solution(s)
Either:
- Perhaps restore some of the funcionality of
isInitialValid
? - Document the usage of
initialErrors
for this since I don’t really know if what I am doing is correct or will be supported in the future. For example, iferrors
get checked more strictly, my trick of setting field errors to''
would stop working. - Suggest a better way to fix this.
Additional context
Your environment
Software | Version(s) |
---|---|
Formik | 2.0.1-rc.9 |
React | 16.8.6 |
TypeScript | none |
Browser | Chome 75.0.3770.100 |
npm/Yarn | npm 6.9.0 |
Operating System | Ubuntu 18.04.2 |
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (11 by maintainers)
Top GitHub Comments
RC9 was a test and isn’t stable
@jaredpalmer I wonder how did you solve the https://github.com/jaredpalmer/formik/issues/1654#issuecomment-509529107? Looking at current master, the
validateAt
is still used there so it means it will crash when some field is missing from schema …https://github.com/jaredpalmer/formik/blob/dce8d31bb07daf0c28c24837c47e629b3aad9cfa/src/Formik.tsx#L205