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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
validateOnMount: Initial value for is valid should be whether the initial values are valid, when validateOnMount is true #2172
Comments
I'd like to help with this |
Go for it! |
Any progress on this? |
Yeah. Putting up a PR in a couple of days |
@omkar-joshi is there any progress on this? If you're still working on the PR, I would really appreciate if you could explain any workarounds for this issue at this time. Also, is there any way to prevent Formik from setting errors after running |
Hi @omkar-joshi any update on this? appreciate your contribution towards OSS. |
Is it just a case of using formik/packages/formik/src/Formik.tsx Lines 366 to 370 in f117c04
|
馃憢 Hi @semopz I've been looking into this a bit this weekend, and I don't think high/low priority will fix this issue unfortunately. Both validate form functions ( Some possible solutions (in user-land or in the library) I can think of are:
Not really sure how to proceed with this, I understand to an extent why isInitialValid was deprecated, but also think removing it isn't serving us well in this scenario. Validate form with low priority:formik/packages/formik/src/Formik.tsx Lines 327 to 331 in f117c04
Login button flash (enabled => disabled) |
Here are a few options in my view: Option 1:
Option 2:
If people think that Option 2 makes sense, I can send a PR. |
I stick on option 2 and use isInitialValid. It fits my needs, it's a simple props to disable a submit button before user completes fields 馃槆 |
Ultimately the state of Where I have experienced this issue, and likely where many others have, is in trying to control enabled/disabled state of a submit button. Typically the button would be disabled while validations are running. The logic would therefore be The problem is that |
Status? |
To add to this discussion, it seems the problem is because computing one possible solution is:
if this makes sense, i can submit a PR |
@vai0 I like your approach. Are you still open for submitting this PR? |
@vai0 push 馃 |
Jan 6, 2020 馃槥 |
Any solutions or workarounds? |
馃悰 Bug report
Current Behavior
When
validateOnMount
is true, initial value forisValid
is 'true', then validation occurs on initial values (which could setisValid
to 'false').Screenshot taken from reproducible example - see console for inconsistency -
isValid
has a different value, for the same form value (empty string in the example):Expected behavior
The first render should return the result of validating the initial values for isValid.
Reproducible example
https://codesandbox.io/s/formik-codesandbox-template-kegrs
Additional context
Would this problem be solved by setting initial errors? I believe possibly, although that would require running validation manually, defeating the purpose of validateOnMount.
The example is a simplification - application code has a far more complex validation schema + more initial values.
Your environment
The text was updated successfully, but these errors were encountered: