fix(ngMaxlength): ignore maxlength when not set to a non-negative integer

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes #9874
This commit is contained in:
Georgios Kalpakas
2014-11-11 11:37:53 +02:00
committed by Pawel Kozlowski
parent 5c1fdff691
commit 92f87b1142
2 changed files with 34 additions and 2 deletions

View File

@@ -2495,6 +2495,16 @@ describe('input', function() {
expect(inputElm).toBeValid();
});
it('should only accept empty values when maxlength is 0', function() {
compileInput('<input type="text" ng-model="value" ng-maxlength="0" />');
changeInputValueTo('');
expect(inputElm).toBeValid();
changeInputValueTo('a');
expect(inputElm).toBeInvalid();
});
it('should accept values of any length when maxlength is negative', function() {
compileInput('<input type="text" ng-model="value" ng-maxlength="-1" />');
@@ -2505,6 +2515,27 @@ describe('input', function() {
expect(inputElm).toBeValid();
});
it('should accept values of any length when maxlength is non-numeric', function() {
compileInput('<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />');
changeInputValueTo('aaaaaaaaaa');
scope.$apply('maxlength = "5"');
expect(inputElm).toBeInvalid();
scope.$apply('maxlength = "abc"');
expect(inputElm).toBeValid();
scope.$apply('maxlength = ""');
expect(inputElm).toBeValid();
scope.$apply('maxlength = null');
expect(inputElm).toBeValid();
scope.someObj = {};
scope.$apply('maxlength = someObj');
expect(inputElm).toBeValid();
});
it('should listen on ng-maxlength when maxlength is observed', function() {
var value = 0;
compileInput('<input type="text" ng-model="value" ng-maxlength="max" attr-capture />');