Description
🐛 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 expected Validation called on : "John"
Suggested solution(s)
Weirdly, setValues
and setFieldValue
implementation are very similar (see below), but only the former is broken
Lines 516 to 521 in d90149e
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 :
Validation called on : {a: 1, b: 0}
Validation called on : {a: 0, b: 2}
In Formik 1.5.8, the output (which feels better to me) would be :
Validation called on : {a: 1, b: 2}
Validation called on : {a: 1, b: 2}
Your environment
Software | Version(s) |
---|---|
Formik | 2.0.3 |
React | 16.11.0 |
TypeScript | - |
Browser | Chrome 78 |
npm/Yarn | Yarn 1.19.0 |
Operating System | Mac OS 10.15 |