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

ng-required stopped working inside ng-if or ng-repeat, version 1.7.6 #16814

Closed
korengal opened this issue Jan 18, 2019 · 4 comments · Fixed by #16820, javascript-indonesias/angular.js#134 or angular-indonesia/angular.js#180
Assignees
Milestone

Comments

@korengal
Copy link

korengal commented Jan 18, 2019

  • [ X] bug report

ng-required stopped working,

I am using AngularJS Material tabs,
I have a condition inside each tab for "required" fields.
I have another condition for showing the tabs or not (ng-if).

plunker: http://next.plnkr.co/edit/g6tieIDq9yaEpNre

In this example, the submit button is not working, but the ng-required for the second input (the hidden one) is false!

another example with ng-repeat:

plunker: http://next.plnkr.co/edit/b7STJ5B4Ktcou83y

In this example, the submit button is not working, the second input (inside the ng repeat) is not required.

if we change angular version back to 1.7.5, its working as excepted.

AngularJS version: 1.7.6

Browser: [all ]

Thanks.

@korengal korengal changed the title ng-required stopped working on 1.7.6 gravity-manipulation (2019-01-17) ng-required stopped working on 1.7.6 inside ng-if or ng-repeat Jan 18, 2019
@korengal korengal changed the title ng-required stopped working on 1.7.6 inside ng-if or ng-repeat ng-required stopped working inside ng-if or ng-repeat, version 1.7.6 Jan 18, 2019
@codymikol
Copy link

codymikol commented Jan 18, 2019

I can confirm that there is some kind of issue with 1.7.6 and ng-required. I have a test that fails in 1.7.6 but passes in 1.7.5

My test asserts that when I set an unrequired field to an empty value the ngModel should be $valid.

After some debugging it looks like my input has the attr ng-required="false" but also has a $error

On the input

image

In the input ngModelCtrl

image

After a bisect and symlinking to my test environment, the commit associated with this issue it 0637a21

codymikol pushed a commit to codymikol/angular.js that referenced this issue Jan 18, 2019
by default ngRequired is set to true, but the original value can be
false and never be updated.

Fixes: angular#16814
codymikol added a commit to codymikol/angular.js that referenced this issue Jan 18, 2019
when ngRequired is initially false the required attribute will now be
updated properly.

Fixes: #angular#16814
@frederikprijck
Copy link
Contributor

Thanks for investigating it @codymikol, it looks like it's idd introduced in @Narretz commit to prevent multiple validators from initializing. Probably a good idea to get @Narretz involved in the PR review ( #16815 ).

@Narretz Narretz added this to the 1.7.x milestone Jan 20, 2019
@Narretz Narretz self-assigned this Jan 20, 2019
Narretz added a commit to Narretz/angular.js that referenced this issue 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 angular#16814
Narretz added a commit to Narretz/angular.js that referenced this issue 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 angular#16814
@evilaliv3
Copy link

evilaliv3 commented Jan 24, 2019

We confirm the issue on the GlobaLeaks as reported by some users here: globaleaks/GlobaLeaks#2495

@petebacondarwin
Copy link
Member

We will release 1.7.7 early next week.

Narretz added a commit to Narretz/angular.js that referenced this issue Jan 25, 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 angular#16814
Narretz added a commit that referenced this issue 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
Narretz added a commit that referenced this issue 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.