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 #7856

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 @@ -2189,7 +2189,7 @@ var maxlengthDirective = function() {
ctrl.$validate();
});
ctrl.$validators.maxlength = function(value) {
return ctrl.$isEmpty(value) || value.length <= maxlength;
return ctrl.$isEmpty(value) || value.toString().length <= maxlength;
};
}
};
Expand All @@ -2207,7 +2207,7 @@ var minlengthDirective = function() {
ctrl.$validate();
});
ctrl.$validators.minlength = function(value) {
return ctrl.$isEmpty(value) || value.length >= minlength;
return ctrl.$isEmpty(value) || value.toString().length >= minlength;
};
}
};
Expand Down
10 changes: 10 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,11 @@ describe('input', function() {

changeInputValueTo('aaa');
expect(inputElm).toBeValid();

scope.$apply(function() {
scope.value = 1234;
});
expect(inputElm).toBeValid();
});

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

changeInputValueTo('aaa');
expect(inputElm).toBeValid();

scope.$apply(function() {
scope.value = 42;
});
expect(inputElm).toBeValid();
});

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