-
-
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
Own Field-level Validation: formik.onChange
handler is not in sync with the formik.values.confirmPassword
#3374
Comments
noticed that there's this dependency: https://www.npmjs.com/package/@johnrom/formik-v3 |
yes, the PR is still open |
@johnrom could you say roughly what the fix is? I'm happy to make a PR to v2 with a fix, but having a starting point or a commit to look at would make it a lot easier. |
The fix is my PR called Formik v3 Umbrella PR. The issue is that there is no way to retrieve the final state in v2 without waiting for the reducer to process messages and trigger an effect. In my v3 PR, I added a redux-like getState API which can be used to get the latest value immediately after an update. |
OK, I figured out what was going wrong. I'm not sure I'll make PR, but at least I can help others with this problem work around the issue. Maybe a PR to the docs about switching from 1x to 2x would do the trick. The issue is that if you use // initialValues = {A: undefined, B: 2, C: 3}
setFieldValue('A', 1);
setFieldValue('B', 2);
setFieldValue('C', 3); It's setting the fields values asynchronously, but validating synchronously, so when setValues({
...values,
A: 1,
B: 2,
C: 3,
}) |
Bug report
Current Behavior
I came up with something that can handle field level validation but I notice the confirm password always fails because the
formik.values.confirmPassword
value is not "in sync" with its current value on the consoleAnd I think it's related to #3368 and #1737
Expected behavior
the validation runs fine
Reproducible example
https://codesandbox.io/s/pedantic-cloud-skr3r
you will see the validation fails and the value on console is not in sync
Suggested solution(s)
Additional context
Your environment
The text was updated successfully, but these errors were encountered: