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

Low priority validation causing problems #1560

Closed
danielkcz opened this issue May 29, 2019 · 10 comments
Closed

Low priority validation causing problems #1560

danielkcz opened this issue May 29, 2019 · 10 comments

Comments

@danielkcz
Copy link

danielkcz commented May 29, 2019

🐛 Bug report

Current Behavior

Basically, when values are modified with setValues, it won't trigger the validation and causes inconsistent outcome - validation errors are still shown despite valid values entered.

Expected behavior

Setting values imperatively should probably be a high priority validation.

Reproducible example

https://codesandbox.io/s/zen-hoover-p66mv

  • focus & blur one of the fields to show error
  • click autofill button
  • error is still shown despite the valid value

Downgrading to RC-1 fixes it.

@rohitkrai03
Copy link

I am facing this issue as well. @jaredpalmer Is there an ETA on this?

@danielkcz
Copy link
Author

danielkcz commented Jul 7, 2019

The current workaround is to call formik.validateForm after the formik.setValues to execute high priority validation. Here is a modified example that shows it... https://codesandbox.io/s/elastic-poincare-6fr2l

Note, it's necessary to call it with the same values otherwise it will see previous ones.

@jaredpalmer
Copy link
Owner

I really wish I never added validation as a side effect of the setXXX methods.

The current workaround as @FredyC would be to avoid validation on setValues and trigger it imperatively.

@FredyC what would the ideal API look like? Do we need to expose validateFormWithLowPriority() and validateFormWithHighPriority()? Also note, that we also have #1526 and could introduce debouncedValidateForm()

@jaredpalmer jaredpalmer changed the title [v2] Low priority validation causing problems Low priority validation causing problems Jul 9, 2019
@jaredpalmer
Copy link
Owner

I've messaged some React team members about this and will report back with a suggested solution.

@danielkcz
Copy link
Author

danielkcz commented Jul 9, 2019

@jaredpalmer I think I've found the culprit...

? validateFormWithLowPriority(state.values)

You are using state.values which is not up to date yet (this isn't synchronous Redux 😉). You need to use values you have in argument :) Perhaps verify there aren't more spots like that, it's a fairly easy mistake to do.

Btw, validateFormWithHighPriority is already exposed as validateForm, but it's far from ideal because if you forget to pass new values, it's the same problem and validating against old values. I would say it's fairly useless as that.

@jaredpalmer
Copy link
Owner

@FredyC that makes sense.

@jaredpalmer
Copy link
Owner

perhaps only handleChange and handleBlur should be low-priority.

@danielkcz
Copy link
Author

Well, I don't think it's a problem to have low priority here, it just needs to validate against new data.

@viniciusdacal
Copy link
Contributor

Anyone working on this? I could give it a shot if you don't mind.

@frantic1048
Copy link
Contributor

Encountered same issue with setFieldValue(), and I found setFieldValue() also uses validateFormWithLowPriority to trigger validation 🤔

version: 2.0.1-rc.13

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

No branches or pull requests

5 participants