@@ -2279,6 +2279,16 @@ describe('input', function() {
22792279 expect ( inputElm ) . toBeValid ( ) ;
22802280 } ) ;
22812281
2282+ it ( 'should only accept empty values when maxlength is 0' , function ( ) {
2283+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="0" />' ) ;
2284+
2285+ changeInputValueTo ( '' ) ;
2286+ expect ( inputElm ) . toBeValid ( ) ;
2287+
2288+ changeInputValueTo ( 'a' ) ;
2289+ expect ( inputElm ) . toBeInvalid ( ) ;
2290+ } ) ;
2291+
22822292 it ( 'should accept values of any length when maxlength is negative' , function ( ) {
22832293 compileInput ( '<input type="text" ng-model="value" ng-maxlength="-1" />' ) ;
22842294
@@ -2289,6 +2299,28 @@ describe('input', function() {
22892299 expect ( inputElm ) . toBeValid ( ) ;
22902300 } ) ;
22912301
2302+ it ( 'should accept values of any length when maxlength is non-numeric' , function ( ) {
2303+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />' ) ;
2304+ changeInputValueTo ( new Array ( 1001 ) . join ( 'a' ) ) ;
2305+
2306+ scope . $apply ( 'maxlength = "abc"' ) ;
2307+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2308+ expect ( inputElm ) . toBeValid ( ) ;
2309+
2310+ scope . $apply ( 'maxlength = ""' ) ;
2311+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2312+ expect ( inputElm ) . toBeValid ( ) ;
2313+
2314+ scope . $apply ( 'maxlength = null' ) ;
2315+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2316+ expect ( inputElm ) . toBeValid ( ) ;
2317+
2318+ scope . someObj = { } ;
2319+ scope . $apply ( 'maxlength = someObj' ) ;
2320+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2321+ expect ( inputElm ) . toBeValid ( ) ;
2322+ } ) ;
2323+
22922324 it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
22932325 var value = 0 ;
22942326 compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
0 commit comments