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

null and false values should not equal each other in deepEqual customizer #2978

Closed
erikrestificar opened this issue May 29, 2017 · 5 comments

Comments

@erikrestificar
Copy link
Contributor

erikrestificar commented May 29, 2017

null and false values should not equal each other in deepEqual customizer. see commit:
a4c1d9f

For example, in a radio group. an unselected radio group (null) is a completely different state from selecting the false option.

@gustavohenke
Copy link
Collaborator

In case all you're trying to do is to verify the selection status of a radio button: you can tell do that by using props such as meta.dirty/meta.pristine instead of checking the values.

@erikrestificar
Copy link
Contributor Author

the issue is that /src/defaultShouldValidate.js uses the deepEqual customizer to determine whether it should validate. For example lets say I have a form with boolean radio fields.

  1. initialValue is null and no radios are selected (invalid state)
  2. user selects the false radio option (valid state)
  3. validation is not triggered because null == false and no change is detected which is incorrect

I'm supplying my own shouldValidate function to get around this issue, but I don't think it makes sense for null == false to be the default behavior, that commit should be rolled back

@j-clark
Copy link

j-clark commented Jun 9, 2017

I've bumped into this as well and have a sandbox reproducing the issue.

To reproduce:

  • click on "No" first
  • see that the radio button doesn't update
  • click elsewhere to blur (it updates)

This doesn't happen when selecting yes first. Only when going from null to false.

@gustavohenke
Copy link
Collaborator

This is yet another case that led to the v7.0.0 release:

undefined and false are now treated as NOT equal. This will affect your dirty/pristine state, as well as whether or not a field is rerendered when the value goes from undefined to false (previously it did not).

@lock
Copy link

lock bot commented Sep 9, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants