Skip to content
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

Validation values are stale #102

Closed
warrenday opened this issue Dec 2, 2019 · 4 comments
Closed

Validation values are stale #102

warrenday opened this issue Dec 2, 2019 · 4 comments

Comments

@warrenday
Copy link

warrenday commented Dec 2, 2019

When using fields such as "TimePicker" or "DatePicker". The values passed into Formiks "validate" or "validateSchema" are incorrect. The callback is showing stale values.

This is only true when validation is called after an onBlur event. onChange works fine.

 <Formik
      initialValues={initialValues}
      validate={values => {
        console.log(values); // values are stale :(
      }}
      onSubmit={onSubmit}
      validateOnChange={false}
      validateOnBlur={true}
    >
    ...
 <Formik
      initialValues={initialValues}
      validate={values => {
        console.log(values); // values are fresh :)
      }}
      onSubmit={onSubmit}
      validateOnChange={true}
      validateOnBlur={false}
    >
    ...
 <Formik
      initialValues={initialValues}
      validate={values => {
        console.log(values); // callback is fired twice, once with fresh values, and once with stale values
      }}
      onSubmit={onSubmit}
      validateOnChange={true}
      validateOnBlur={true}
    >
    ...
@nimiak
Copy link

nimiak commented Dec 4, 2019

This is related to jaredpalmer/formik#2083.

Works fine with formik v1.5.8

@jannikbuschke
Copy link
Owner

@warrenday is this still an issue with formik v2.0.8?

@ericdvb
Copy link

ericdvb commented Dec 26, 2019

@warrenday I'm seeing this behavior as well after upgrading to latest Formik. Can't speak to the specific way you have your form / field set up, but in our case in v1.5.2 (previous version our project was on) the validation fires twice on change, the second time with the fresh value. In v2.0.8, it fires twice on change, the second time using the stale value.

It also seems that setting validateOnChange to false doesn't have the expected effect (validation fires on change anyway, but only once, and with the stale value) 😕 but that's a separate issue.

@jannikbuschke
Copy link
Owner

this should be fixed in v1.6.3 and v1.7.0-beta.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants