Skip to content

Commit b35907a

Browse files
committedJun 16, 2014
fix(NgModel): use string representation of the value in the ngMinlength and ngMaxlength
Fixes angular#7848
1 parent 928c7ec commit b35907a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎src/ng/directive/input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ var maxlengthDirective = function() {
21892189
ctrl.$validate();
21902190
});
21912191
ctrl.$validators.maxlength = function(value) {
2192-
return ctrl.$isEmpty(value) || value.length <= maxlength;
2192+
return ctrl.$isEmpty(value) || value.toString().length <= maxlength;
21932193
};
21942194
}
21952195
};
@@ -2207,7 +2207,7 @@ var minlengthDirective = function() {
22072207
ctrl.$validate();
22082208
});
22092209
ctrl.$validators.minlength = function(value) {
2210-
return ctrl.$isEmpty(value) || value.length >= minlength;
2210+
return ctrl.$isEmpty(value) || value.toString().length >= minlength;
22112211
};
22122212
}
22132213
};

‎test/ng/directive/inputSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,11 @@ describe('input', function() {
14001400

14011401
changeInputValueTo('aaa');
14021402
expect(inputElm).toBeValid();
1403+
1404+
scope.$apply(function() {
1405+
scope.value = 1234;
1406+
});
1407+
expect(inputElm).toBeValid();
14031408
});
14041409

14051410
it('should listen on ng-minlength when minlength is observed', function() {
@@ -1446,6 +1451,11 @@ describe('input', function() {
14461451

14471452
changeInputValueTo('aaa');
14481453
expect(inputElm).toBeValid();
1454+
1455+
scope.$apply(function() {
1456+
scope.value = 42;
1457+
});
1458+
expect(inputElm).toBeValid();
14491459
});
14501460

14511461
it('should listen on ng-maxlength when maxlength is observed', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.