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

minlength validator binded to ng-model not input #12158

Closed
piernik opened this issue Jun 18, 2015 · 2 comments
Closed

minlength validator binded to ng-model not input #12158

piernik opened this issue Jun 18, 2015 · 2 comments

Comments

@piernik
Copy link

piernik commented Jun 18, 2015

I'm using custom directive to build my form.
Like <my-input ng-model="vm.value" required="true" minlength="6">

This example shows that in validation required is bind to ng-model and works great. But minlength or ng-minlength is different - I suppose it works only with input tag.

Can You bing ng-minlength with ng-model?

Should I make my own validator?

@gkalpak
Copy link
Member

gkalpak commented Jun 18, 2015

The non ng- prefixed attributes will work correctly on any element (as long as ngModelis present).

The boolean attributes (such as ngDisabled or ngRequired) will also work correctly on any element (as long as ngModelis present).

The (so called) aliased attributes (ngMin, ngMax, ngMinLength, ngMaxLength, ngPattern) on the other hand will only work on <input> or <textarea> elements.

Demo


I am not implying that it is OK (nor do I know why); I am just describing how things work atm.

So, a quick workaround (until this is resolved or decided to be left as is) is to use the non ng- prefixed versions.

@Narretz
Copy link
Contributor

Narretz commented Jun 18, 2015

Since we try to support custom controls with ng-model, these directives should probably not be restricted by element.

@Narretz Narretz added this to the Backlog milestone Aug 4, 2015
@Narretz Narretz self-assigned this Aug 4, 2015
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 23, 2015
`ng-(pattern|minlength|maxlength)` directives will now validate the
`ngModel` when on an element that is not an `input` or
a `textarea`.
The commit also adds a test for `ng-required`, although that validator
worked on all elements before this fix.

Fixes angular#12158
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 23, 2015
`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.
The commit also adds a test for `ng-required`, although that validator
worked on all elements before this fix.

Fixes angular#12158
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 27, 2015
`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 aforementioned validators
were extracted into  separate directives, whereas the aliased attribute
handling assumes the validators will only exist on `input|textarea`

The commit also adds a test for `ng-required`, although that validator
worked on all elements before this fix.

Fixes angular#12158
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 28, 2015
`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
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 31, 2015
`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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.