-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngModel): let aliased validator directives work on any element #12658
Conversation
f2ca7e7
to
1c462c7
Compare
Doesn't it also affect |
Hmm ... min / ngMin and max / ngMax validators are only added for But before that, we made it so that ngPattern, ngMaxlength, ngMinlength, ngMax and ngMin will set their corresponding non-ng attributes, so that the validator directives only have to observe the non-ng attributes (instead of having another set of directives that watch ngXYZ), see d9b90d7 and 25541c1 That's why the aliased attribute path in $set would only set the attributes for input and textarea. It's a bit confusing, but there I can't think of any drawbacks atm. There's just the case that e.g. ngMax on a non-input element will set max, too and make it observable, without actually adding a validator. |
1c462c7
to
b063d30
Compare
Hm...you are right...weird (that all alliased attributes are directives except for But this is not an ideal world, so this LGTM as is 👍 |
It seems we have basically split our validators into two groups: generic one's that validate the input / viewValue (which is always a string) and specific one's, such as date / number. min / max really only make sense for date / number, so it'd be hard to make them generic. |
b063d30
to
b04fc58
Compare
`ng(Pattern|Minlength|Maxlength)` directives will now validate the `ngModel` when on an element that is not an `input` or a `textarea`. Previously, only their HTML5 counterparts worked on every element. This is because the three validators were extracted into separate directives (see 26d91b6 and 1be9bb9), whereas the aliased attribute handling assumes the validators will only exist on `input|textarea` (see d9b90d7 and 25541c1). Since `ngMin` and `ngMax` are also aliased attributes, this means observers of `min` and `max` will be fired if `ngMin` and `ngMax` change. This will happen on any element, even if it does not have an `ngModel`. However, since min/max validators are only ever added as part of the `input[number|textarea]` types, even if the element has an `ngModel`, no validators will be added. Finally the commit also tests that `ng-required` works on any element, although that validator worked on all elements before this fix. Fixes angular#12158 Closes angular#12658
`ng(Pattern|Minlength|Maxlength)` directives will now validate the `ngModel` when on an element that is not an `input` or a `textarea`. Previously, only their HTML5 counterparts worked on every element. This is because the three validators were extracted into separate directives (see 26d91b6 and 1be9bb9), whereas the aliased attribute handling assumes the validators will only exist on `input|textarea` (see d9b90d7 and 25541c1). Since `ngMin` and `ngMax` are also aliased attributes, this means observers of `min` and `max` will be fired if `ngMin` and `ngMax` change. This will happen on any element, even if it does not have an `ngModel`. However, since min/max validators are only ever added as part of the `input[number|textarea]` types, even if the element has an `ngModel`, no validators will be added. Finally the commit also tests that `ng-required` works on any element, although that validator worked on all elements before this fix. Fixes angular#12158 Closes angular#12658
b04fc58
to
aeb186a
Compare
ng-(pattern|minlength|maxlength)
directives will now validate thengModel
when on an element that is not aninput
ora
textarea
.The commit also adds a test for
ng-required
, although that validatorworked on all elements before this fix.
Fixes #12158