Open vvatikiotis opened 4 years ago
Is'nt validateSync is a method of Yup, not of Formik?
Formik will check which type (async, sync) yup validation is used in the validateYupSchema.
And I guess the culprit is this promise in the runValidationSchema.
validateSync
is a method of Yup, but Formik provides no way to call it. Formik defines the validateYupSchema
function, which takes in a flag controlling sync/async. However, that function is only ever called with sync = false
.
This makes using Yup pretty annoying, because values
and errors
can get out of sync. So for example, if you use isValid
to determine whether to disable a button, the button may "flicker" when you change your form because isValid
is not consistent with validationSchema.isValidSync(values)
.
We're having the same problem.
After a consecutive call of setFieldTouched
then field prop onChange
, two async validation are engaged.
In our case onChange
values trigger a shorter validation in the yup schema, which led onChange
validation result to be override by setFieldTouched
validation result that ends later (with values that are out of sync).
Errors kept should always come from the latest validation call, not latest validation resolvation.
❓Question
Seriously, for immediate help, just ask your question on the #formik channel on Reactiflux.
I apologise for this question, however I had no luck on Reactiflux (so far).
Reproducible example
https://codesandbox.io/s/still-sun-zi4kt
Environment
So I have the following bare minimum one field form and I use Yup for validation. What I need is a way to get
values
anderrors
change synchronously. The following should (?) work but it doesn't:In this example, when the field is filled,
values
anderrors
change asynchronously, i.e.values
change anderrors
change after next render. Is there a way to 'sync'values
anderrors
? Yup's.validateSync
seemed like a good candidate.