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

fix(NgModel): use string representation of the value in the ngMinlength and ngMaxlength v1.2.x #7858

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ 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) || value.toString().length >= minlength, value);
};

ctrl.$parsers.push(minLengthValidator);
Expand All @@ -595,7 +595,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.ngMaxlength) {
var maxlength = int(attr.ngMaxlength);
var maxLengthValidator = function(value) {
return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) || value.length <= maxlength, value);
return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) || value.toString().length <= maxlength, value);
};

ctrl.$parsers.push(maxLengthValidator);
Expand Down
20 changes: 20 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,16 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});

it('should use string representation of the value', function(){
compileInput('<input type="text" ng-model="value" ng-minlength="3" />');

scope.$apply(function() {
scope.value = 123;
});

expect(inputElm).toBeValid();
});
});


Expand All @@ -775,6 +785,16 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});

it('should use string representation of the value', function(){
compileInput('<input type="text" ng-model="value" ng-maxlength="5" />');

scope.$apply(function() {
scope.value = 123;
});

expect(inputElm).toBeValid();
});
});


Expand Down