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

Commit d08efc3

Browse files
committed
feat(ngMaxlength): add support for disabling max length limit
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to #9874 Closes #9995
1 parent 2b41a58 commit d08efc3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ var maxlengthDirective = function() {
26752675
ctrl.$validate();
26762676
});
26772677
ctrl.$validators.maxlength = function(modelValue, viewValue) {
2678-
return ctrl.$isEmpty(modelValue) || viewValue.length <= maxlength;
2678+
return (maxlength < 0) || ctrl.$isEmpty(modelValue) || (viewValue.length <= maxlength);
26792679
};
26802680
}
26812681
};

test/ng/directive/inputSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,16 @@ describe('input', function() {
24522452
expect(inputElm).toBeValid();
24532453
});
24542454

2455+
it('should accept values of any length when maxlength is negative', function() {
2456+
compileInput('<input type="text" ng-model="value" ng-maxlength="-1" />');
2457+
2458+
changeInputValueTo('');
2459+
expect(inputElm).toBeValid();
2460+
2461+
changeInputValueTo('aaaaaaaaaa');
2462+
expect(inputElm).toBeValid();
2463+
});
2464+
24552465
it('should listen on ng-maxlength when maxlength is observed', function() {
24562466
var value = 0;
24572467
compileInput('<input type="text" ng-model="value" ng-maxlength="max" attr-capture />');

0 commit comments

Comments
 (0)