@@ -2279,6 +2279,16 @@ describe('input', function() {
2279
2279
expect ( inputElm ) . toBeValid ( ) ;
2280
2280
} ) ;
2281
2281
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
+
2282
2292
it ( 'should accept values of any length when maxlength is negative' , function ( ) {
2283
2293
compileInput ( '<input type="text" ng-model="value" ng-maxlength="-1" />' ) ;
2284
2294
@@ -2293,6 +2303,28 @@ describe('input', function() {
2293
2303
expect ( inputElm ) . toBeValid ( ) ;
2294
2304
} ) ;
2295
2305
2306
+ it ( 'should accept values of any length when maxlength is non-numeric' , function ( ) {
2307
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />' ) ;
2308
+ changeInputValueTo ( new Array ( 1001 ) . join ( 'a' ) ) ;
2309
+
2310
+ scope . $apply ( 'maxlength = "abc"' ) ;
2311
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2312
+ expect ( inputElm ) . toBeValid ( ) ;
2313
+
2314
+ scope . $apply ( 'maxlength = ""' ) ;
2315
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2316
+ expect ( inputElm ) . toBeValid ( ) ;
2317
+
2318
+ scope . $apply ( 'maxlength = null' ) ;
2319
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2320
+ expect ( inputElm ) . toBeValid ( ) ;
2321
+
2322
+ scope . someObj = { } ;
2323
+ scope . $apply ( 'maxlength = someObj' ) ;
2324
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2325
+ expect ( inputElm ) . toBeValid ( ) ;
2326
+ } ) ;
2327
+
2296
2328
it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2297
2329
var value = 0 ;
2298
2330
compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
0 commit comments