@@ -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
@@ -2289,6 +2299,27 @@ describe('input', function() {
2289
2299
expect ( inputElm ) . toBeValid ( ) ;
2290
2300
} ) ;
2291
2301
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 ( 'aaaaaaaaaa' ) ;
2305
+
2306
+ scope . $apply ( 'maxlength = "5"' ) ;
2307
+ expect ( inputElm ) . toBeInvalid ( ) ;
2308
+
2309
+ scope . $apply ( 'maxlength = "abc"' ) ;
2310
+ expect ( inputElm ) . toBeValid ( ) ;
2311
+
2312
+ scope . $apply ( 'maxlength = ""' ) ;
2313
+ expect ( inputElm ) . toBeValid ( ) ;
2314
+
2315
+ scope . $apply ( 'maxlength = null' ) ;
2316
+ expect ( inputElm ) . toBeValid ( ) ;
2317
+
2318
+ scope . someObj = { } ;
2319
+ scope . $apply ( 'maxlength = someObj' ) ;
2320
+ expect ( inputElm ) . toBeValid ( ) ;
2321
+ } ) ;
2322
+
2292
2323
it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2293
2324
var value = 0 ;
2294
2325
compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
0 commit comments