@@ -2495,6 +2495,16 @@ describe('input', function() {
2495
2495
expect ( inputElm ) . toBeValid ( ) ;
2496
2496
} ) ;
2497
2497
2498
+ it ( 'should only accept empty values when maxlength is 0' , function ( ) {
2499
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="0" />' ) ;
2500
+
2501
+ changeInputValueTo ( '' ) ;
2502
+ expect ( inputElm ) . toBeValid ( ) ;
2503
+
2504
+ changeInputValueTo ( 'a' ) ;
2505
+ expect ( inputElm ) . toBeInvalid ( ) ;
2506
+ } ) ;
2507
+
2498
2508
it ( 'should accept values of any length when maxlength is negative' , function ( ) {
2499
2509
compileInput ( '<input type="text" ng-model="value" ng-maxlength="-1" />' ) ;
2500
2510
@@ -2505,6 +2515,27 @@ describe('input', function() {
2505
2515
expect ( inputElm ) . toBeValid ( ) ;
2506
2516
} ) ;
2507
2517
2518
+ it ( 'should accept values of any length when maxlength is non-numeric' , function ( ) {
2519
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />' ) ;
2520
+ changeInputValueTo ( 'aaaaaaaaaa' ) ;
2521
+
2522
+ scope . $apply ( 'maxlength = "5"' ) ;
2523
+ expect ( inputElm ) . toBeInvalid ( ) ;
2524
+
2525
+ scope . $apply ( 'maxlength = "abc"' ) ;
2526
+ expect ( inputElm ) . toBeValid ( ) ;
2527
+
2528
+ scope . $apply ( 'maxlength = ""' ) ;
2529
+ expect ( inputElm ) . toBeValid ( ) ;
2530
+
2531
+ scope . $apply ( 'maxlength = null' ) ;
2532
+ expect ( inputElm ) . toBeValid ( ) ;
2533
+
2534
+ scope . someObj = { } ;
2535
+ scope . $apply ( 'maxlength = someObj' ) ;
2536
+ expect ( inputElm ) . toBeValid ( ) ;
2537
+ } ) ;
2538
+
2508
2539
it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2509
2540
var value = 0 ;
2510
2541
compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
0 commit comments