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

Sequential setFieldValue runs validation incorrectly #3345

Open
WebTravel opened this issue Sep 14, 2021 · 4 comments
Open

Sequential setFieldValue runs validation incorrectly #3345

WebTravel opened this issue Sep 14, 2021 · 4 comments
Labels
automerge automerge label for kodiak Type: Bug

Comments

@WebTravel
Copy link

WebTravel commented Sep 14, 2021

Bug report

Current Behavior

User has three fields. "fillFields", "firstName", "lastName".
fill - is a radio button. When user clicks on this fields both another fields are filling some values.
Filling of this values happen in useEffect hook. And all works fine without validation. It doesn't work properly.

I have the example. https://codesandbox.io/s/red-glade-x3y32
Step to reproduce this bug:

  1. Fill firstName
  2. Fill lasName
  3. Clear firstName
  4. Clear lastName
  5. You see the errors about requirement fields above
  6. Click to radio button "Fill fields"
  7. The error one of field is cleared, but the error second field still display to user

Then if i click outside fillFields. Validation runs again after onBlur and the error disappears. But it has to disappear after onChange. The validation needs to call after updating of values state.

Expected behavior

The errors doesn't appear to user for all fields.

Reproducible example

https://codesandbox.io/s/red-glade-x3y32?file=/src/App.js

Additional context

I use useFormik hook. I suppose validation doesn't has to run before the state was updated.

Your environment

Software Version(s)
Formik 17.0.2
React 2.2.9
Operating System Any
@johnrom
Copy link
Collaborator

johnrom commented Sep 14, 2021

@johnrom johnrom added the automerge automerge label for kodiak label Sep 14, 2021
@WebTravel
Copy link
Author

WebTravel commented Sep 15, 2021

Thanks for the answer, but this demo doesn't work

@johnrom
Copy link
Collaborator

johnrom commented Sep 15, 2021

For some reason codesandbox hasn't been updating after a few saves lately. I updated it above, so hopefully it saved.

@halcarleton
Copy link

Fixed in v3 beta #3231

https://codesandbox.io/s/crazy-matan-dno1x?file=/src/App.js

Is there going to be a fix released to 2.x.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge automerge label for kodiak Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants