@@ -2326,6 +2326,16 @@ describe('input', function() {
2326
2326
expect ( inputElm ) . toBeValid ( ) ;
2327
2327
} ) ;
2328
2328
2329
+ it ( 'should only accept empty values when maxlength is 0' , function ( ) {
2330
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="0" />' ) ;
2331
+
2332
+ changeInputValueTo ( '' ) ;
2333
+ expect ( inputElm ) . toBeValid ( ) ;
2334
+
2335
+ changeInputValueTo ( 'a' ) ;
2336
+ expect ( inputElm ) . toBeInvalid ( ) ;
2337
+ } ) ;
2338
+
2329
2339
it ( 'should accept values of any length when maxlength is negative' , function ( ) {
2330
2340
compileInput ( '<input type="text" ng-model="value" ng-maxlength="-1" />' ) ;
2331
2341
@@ -2336,6 +2346,27 @@ describe('input', function() {
2336
2346
expect ( inputElm ) . toBeValid ( ) ;
2337
2347
} ) ;
2338
2348
2349
+ it ( 'should accept values of any length when maxlength is non-numeric' , function ( ) {
2350
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />' ) ;
2351
+ changeInputValueTo ( 'aaaaaaaaaa' ) ;
2352
+
2353
+ scope . $apply ( 'maxlength = "5"' ) ;
2354
+ expect ( inputElm ) . toBeInvalid ( ) ;
2355
+
2356
+ scope . $apply ( 'maxlength = "abc"' ) ;
2357
+ expect ( inputElm ) . toBeValid ( ) ;
2358
+
2359
+ scope . $apply ( 'maxlength = ""' ) ;
2360
+ expect ( inputElm ) . toBeValid ( ) ;
2361
+
2362
+ scope . $apply ( 'maxlength = null' ) ;
2363
+ expect ( inputElm ) . toBeValid ( ) ;
2364
+
2365
+ scope . someObj = { } ;
2366
+ scope . $apply ( 'maxlength = someObj' ) ;
2367
+ expect ( inputElm ) . toBeValid ( ) ;
2368
+ } ) ;
2369
+
2339
2370
it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2340
2371
var value = 0 ;
2341
2372
compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
0 commit comments