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

fix(input): ngMinlength/ngMaxlength should not invalidate non-stringlike values #6002

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Jan 27, 2014

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

@IgorMinar IgorMinar added this to the 1.3.0-beta.3 milestone Mar 17, 2014
@@ -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);
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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
@caitp
Copy link
Contributor Author

caitp commented Sep 25, 2014

I believe this was basically fixed by 77ce5b8

@caitp caitp closed this Sep 25, 2014
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.

ngMinlength and ngMaxlength attribute not bind value, when model value is type Number
6 participants