You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the reason for this problem is that dispatch is an async function, so there is no way to know when the state has been updated.
For the setValue method, I think we can easily pass the values parameter into validateFormWithLowPriority method, but for the setFieldValue method, I have no idea how to deal with it.
🐛 Bug report
Current Behavior
Using
setValues
with a form-level<Formik validate>
will call validation function on the previous state.Expected behavior
Validation should be called on the newly set values. Works as expected with Formik 1.5.8
Reproducible example
Very minimal example : https://codesandbox.io/s/formik-codesandbox-template-zm8tc
Just press "Set Values" button and watch console :
Validation called on : "old name"
appears instead of expectedValidation called on : "John"
Suggested solution(s)
Weirdly,
setValues
andsetFieldValue
implementation are very similar (see below), but only the former is brokenformik/src/Formik.tsx
Lines 516 to 521 in d90149e
formik/src/Formik.tsx
Lines 533 to 546 in d90149e
Related problem ?
Calling
setFieldValue
multiple times has a different behaviour regarding validation since v2.Minimal example : https://codesandbox.io/s/formik-codesandbox-template-f2huz
Just press "Set Values" button and watch console :
In Formik 1.5.8, the output (which feels better to me) would be :
Your environment
The text was updated successfully, but these errors were encountered: