File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -2610,9 +2610,9 @@ var maxlengthDirective = function() {
2610
2610
link : function ( scope , elm , attr , ctrl ) {
2611
2611
if ( ! ctrl ) return ;
2612
2612
2613
- var maxlength = 0 ;
2613
+ var maxlength = - 1 ;
2614
2614
attr . $observe ( 'maxlength' , function ( value ) {
2615
- maxlength = int ( value ) || 0 ;
2615
+ maxlength = int ( value ) || - 1 ;
2616
2616
ctrl . $validate ( ) ;
2617
2617
} ) ;
2618
2618
ctrl . $validators . maxlength = function ( modelValue , viewValue ) {
Original file line number Diff line number Diff line change @@ -2293,6 +2293,28 @@ describe('input', function() {
2293
2293
expect ( inputElm ) . toBeValid ( ) ;
2294
2294
} ) ;
2295
2295
2296
+ it ( 'should accept values of any length when maxlength is non-numeric' , function ( ) {
2297
+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="{{maxlength}}" />' ) ;
2298
+ changeInputValueTo ( new Array ( 1001 ) . join ( 'a' ) ) ;
2299
+
2300
+ scope . $apply ( 'maxlength = "abc"' ) ;
2301
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2302
+ expect ( inputElm ) . toBeValid ( ) ;
2303
+
2304
+ scope . $apply ( 'maxlength = ""' ) ;
2305
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2306
+ expect ( inputElm ) . toBeValid ( ) ;
2307
+
2308
+ scope . $apply ( 'maxlength = null' ) ;
2309
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2310
+ expect ( inputElm ) . toBeValid ( ) ;
2311
+
2312
+ scope . someObj = { } ;
2313
+ scope . $apply ( 'maxlength = someObj' ) ;
2314
+ expect ( inputElm . val ( ) . length ) . toBe ( 1000 ) ;
2315
+ expect ( inputElm ) . toBeValid ( ) ;
2316
+ } ) ;
2317
+
2296
2318
it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2297
2319
var value = 0 ;
2298
2320
compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
You can’t perform that action at this time.
0 commit comments