mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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:
committed by
Pawel Kozlowski
parent
5c1fdff691
commit
92f87b1142
@@ -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 />');
|
||||
|
||||
Reference in New Issue
Block a user