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

fix(forms): remove equalsTo validator #15050

Merged
merged 1 commit into from
Mar 14, 2017
Merged

Conversation

kara
Copy link
Contributor

@kara kara commented Mar 9, 2017

We are removing the equalsTo validator introduced in 4.0.0.beta.6 because upon review, the concept is inconsistent with and breaks the guarantees of the validation model.

This validator introduces dependencies between sibling controls. This is problematic because our validation model propagates changes up the tree. If you change the value of a form control in the UI, the form control in question is validated, then its parent, and its parent, and so on. Its siblings are not re-validated as their values have not changed. This allows us to skip checking subtrees that haven't updated and keep validation fast.

Because of this, the validator doesn't work as expected. If you add the equalsTo validator onto control "one", when you change the value of control "two" in the UI, the validation status of control "one" will not be re-calculated. Only changes initiated in control "one" itself will actually update its validation status. Even if you add another equalsTo validator on control "two", it will still not be validated on changes to control "one" and both controls' validation statuses will often be incorrect (see plunker here: http://plnkr.co/edit/4gcrKXs47nf6NTbJHJPw?p=preview).

Validating between sibling controls is something that is already possible in the framework with group validators. We generally recommend moving up a level to validate between sibling controls. As validation propagates up, the group will always be updated when the value of any of its descendants changes.

Based on these mismatches, this validator does not belong at the framework level.

@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 9, 2017
@kara kara requested review from StephenFluin and IgorMinar March 9, 2017 22:02
@Toxicable
Copy link

As mentioned about your note on validating at a group level would it not be fitting to move this validator there then? Or would it still not belong in the framework even without those issues?

@kara
Copy link
Contributor Author

kara commented Mar 9, 2017

@Toxicable Given that a group validator only takes a line or two to implement, it seems straightforward enough to leave up to the individual developer. Different projects tend to have very different needs for what's considered "equal", so people will often have to implement their own customization for equality checks anyway. One project might want to check ID only, another might want to do a deep check, etc. Supporting all these cases isn't really possible without asking for a function (which is essentially what we have now).

By the way, wanted to say thanks for contributing the original PR. It sucks that we had to revert. I hope this doesn't discourage you from contributing more to the framework going forward; we appreciate it :)

@Toxicable
Copy link

@kara That's a fair point about different implementations of equality, thanks for explaining that. I understand that this is how things work sometimes and don't worry t hasn't discouraged me from contributing, I will help out were I can.

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please improve the commit message to explain why this is being removed and why that's ok (because the API was introduced only in a beta and we found it to be incorrect before the launch).

kara added a commit to kara/angular that referenced this pull request Mar 10, 2017
This API was introduced only in a beta release, and is being removed because we found it to be incorrect prior to launch. For more information about why this is being removed, see angular#15050.
@kara kara added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 10, 2017
@chuckjaz
Copy link
Contributor

This change needs to be rebased.

This API was introduced only in a beta release, and is being removed because we found it to be incorrect prior to launch. For more information about why this is being removed, see angular#15050.
@kara
Copy link
Contributor Author

kara commented Mar 13, 2017

@IgorMinar This needs approval again after the rebase (folder moved).

@IgorMinar IgorMinar self-requested a review March 13, 2017 19:02
@chuckjaz chuckjaz merged commit 778f7d6 into angular:master Mar 14, 2017
@kara kara added this to the 4.0.0-blockers milestone Mar 14, 2017
@dietergeerts
Copy link

equalsTo can be seen in two ways: the way you guys are explaining it and why it got removed, or that a field must be identical to another, like a repeat password field, and then, that validation must only be applied to that second fields, so then there is no problem, so please reconsider this decision!

@kara
Copy link
Contributor Author

kara commented Mar 17, 2017

@dietergeerts Even if you only care about validating the second field, the second field's validation would also be wrong. Any edits to the first field would not run the second field's validation.

In other words, if you type:

  1. "a" into the first field
  2. "a" into the second field
  3. then "b" into the first field (so it reads "ab")

They would not be equal, but the second field would still report VALID because it would not be notified of the change in "a".

SamVerschueren pushed a commit to SamVerschueren/angular that referenced this pull request Mar 18, 2017
This API was introduced only in a beta release, and is being removed because we found it to be incorrect prior to launch. For more information about why this is being removed, see angular#15050.
@dietergeerts
Copy link

True, but maybe we need to have the possibility to rerun a validator on field B when field A changes?

@fmalcher
Copy link
Contributor

Can you mark this one as breaking change (or at least extra highlighted) in the change log?
I know this has been introduced in a beta release ;-) However, when just listed under "bug fixes" some might miss that one.
Thanks! 😎🆖 @kara @chuckjaz @IgorMinar

@mlc-mlapis
Copy link
Contributor

@dietergeerts And updateValueAndValidity method is not enough as in other cross validation cases?

@Toxicable
Copy link

Toxicable commented Mar 19, 2017

@dietergeerts The issues described will still occur, but these short comings of the validator can be fix by implementing it at FormGroup level rather than at a FormControl level.

asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
This API was introduced only in a beta release, and is being removed because we found it to be incorrect prior to launch. For more information about why this is being removed, see angular#15050.
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
This API was introduced only in a beta release, and is being removed because we found it to be incorrect prior to launch. For more information about why this is being removed, see angular#15050.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants