question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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, if errors 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:closed
  • Created 4 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredpalmercommented, Jul 8, 2019

RC9 was a test and isn’t stable

0reactions
danielkczcommented, Aug 11, 2019

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

'isValid' is always false - Stack Overflow
isValid to be true when I enter text into the input (and so satisfy the required condition). Here is an example code:
Read more >
Page.IsValid always True - MSDN - Microsoft
I have a RequiredFieldValidator on a text box but when my button is clicked the Page.IsValid always returns True, even if the field...
Read more >
Review Contractor (RC) Client Java User Guide and ... - CMS
Appendix A:Description of Fields on RC Client Tabs . ... The RC does not need to log in to the esMD cloud environment...
Read more >
Controlling Radiated Emissions by Design - Springer
9. Reducing Radiated EMI via Internal Cabling and Packaging 152 ... In this region, all the real and imaginary terms in field equations...
Read more >
Messages and Troubleshooting Guide - IBM
characteristics data are not valid. Explanation. {0}. User response. Correct the values accordingly. BPOK5017. All data values in the requested.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found