Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngRequired): set error correctly when inside ngRepeat and false b… #16820

Merged
merged 1 commit into from Jan 26, 2019

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Jan 21, 2019

…y default

Previously, in the required validator, we would read the required setting directly from attr.required,
where it is set by ngRequired.

However, when the control is inside ngRepeat, ngRequired sets it only after a another digest has
passed, which means the initial validation run of ngModel does not include the correct required
setting. (Before commit 0637a21 this would not have been a problem,
as every observed value change triggered a validation).

We now use the initially parsed value from ngRequired in the validator.

Fixes #16814

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change?

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:

var elm = helper.compileInput(
'<div ng-repeat="input in [0]">' +
'<input type="text" ng-ref="refs.input" ng-ref-read="ngModel" ng-model="value" ng-required="isRequired" validation-spy="required" />'
+ '</div>'
Copy link
Member

Choose a reason for hiding this comment

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

The + sign placement seems weird (i.e. inconsistent - which is the ultimate form of weird 😛).
Did the linter have you do it like this, or is it a personal preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, this happened because I tested without ngRepeat, and switching between with / without is easier if the concat plusses are at the start of the line

…y default

Previously, in the required validator, we would read the required setting directly
from attr.required, where it is set by ngRequired.

However, when the control is inside ngRepeat, ngRequired sets it only after a another digest has
passed, which means the initial validation run of ngModel does not include the correct required
setting. (Before commit 0637a21 this would not have been a problem,
as every observed value change triggered a validation).

We now use the initially parsed value from ngRequired in the validator.

Fixes angular#16814
@Narretz Narretz merged commit 005dd97 into angular:master Jan 26, 2019
@Narretz Narretz deleted the fix-ngRequired branch January 26, 2019 10:31
Narretz added a commit that referenced this pull request Jan 26, 2019
…y default

Previously, in the required validator, we would read the required setting directly
from attr.required, where it is set by ngRequired.

However, when the control is inside ngRepeat, ngRequired sets it only after a another digest has
passed, which means the initial validation run of ngModel does not include the correct required
setting. (Before commit 0637a21 this would not have been a problem,
as every observed value change triggered a validation).

We now use the initially parsed value from ngRequired in the validator.

Fixes #16814
Closes #16820
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ng-required stopped working inside ng-if or ng-repeat, version 1.7.6
4 participants