-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(input): ngMinlength/ngMaxlength should not invalidate non-stringlike values #6002
Conversation
@@ -518,7 +518,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { | |||
if (attr.ngMinlength) { | |||
var minlength = int(attr.ngMinlength); | |||
var minLengthValidator = function(value) { | |||
return validate(ctrl, 'minlength', ctrl.$isEmpty(value) || value.length >= minlength, value); | |||
return validate(ctrl, 'minlength', ctrl.$isEmpty(value) || | |||
(isDefined(value.length) ? value.length : Infinity) >= minlength, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this just be
!isDefined(value.length) || value.length >= minlength
and similar for maxlength?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined >= 10
for example, would always evaluate to false (and would thus invalidate empty strings, which is not the correct behaviour in html5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see whar you're saying, I can't recall the exact reasons since it's been a while since I wrote this, but there was some mechanical issue involved with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it slightly differently and yeah, works well enough.
…ike values A regression reported in angular#5936 shows that prior to cdc4d48, an input with an ngMinlength or ngMaxlength validator would not invalidate values where value.length was undefined. The behaviour of this validator is still incorrect in the case of objects with a length property which are not arrays or strings, and will most likely remain that way. This cannot change as it is possibly desirable to use ngMinlength/ngMaxlength in conjunction with ngList. Closes angular#5936 Closes angular#6000
02dc2aa
to
fd2d6c0
Compare
I believe this was basically fixed by 77ce5b8 |
A regression reported in #5936 shows that prior to cdc4d48, an input with an ngMinlength or ngMaxlength validator would not invalidate values where value.length was undefined.
This patch addresses this by making use of the Infinity global when a value's length property is undefined.
The behaviour of this validator is still incorrect in the case of objects with a length property which are not arrays or strings, and will most likely remain that way. This cannot change as it is possibly desirable to use ngMinlength/ngMaxlength in conjunction with ngList.
Closes #5936
Closes #6000