This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ var maxlengthDirective = function() {
65
65
ctrl . $validate ( ) ;
66
66
} ) ;
67
67
ctrl . $validators . maxlength = function ( modelValue , viewValue ) {
68
- return ( maxlength < 0 ) || ctrl . $isEmpty ( modelValue ) || ( viewValue . length <= maxlength ) ;
68
+ return ( maxlength < 0 ) || ctrl . $isEmpty ( viewValue ) || ( viewValue . length <= maxlength ) ;
69
69
} ;
70
70
}
71
71
} ;
Original file line number Diff line number Diff line change @@ -410,6 +410,20 @@ describe('validators', function() {
410
410
expect ( $rootScope . value ) . toBe ( 12345 ) ;
411
411
expect ( $rootScope . form . input . $error . maxlength ) . toBeUndefined ( ) ;
412
412
} ) ;
413
+
414
+ it ( 'should validate emptiness against the viewValue' , function ( ) {
415
+ var inputElm = helper . compileInput ( '<input type="text" name="input" ng-model="value" maxlength="10" />' ) ;
416
+
417
+ var ctrl = inputElm . controller ( 'ngModel' ) ;
418
+ spyOn ( ctrl , '$isEmpty' ) . andCallThrough ( ) ;
419
+
420
+ ctrl . $parsers . push ( function ( value ) {
421
+ return value + '678' ;
422
+ } ) ;
423
+
424
+ helper . changeInputValueTo ( '12345' ) ;
425
+ expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
426
+ } ) ;
413
427
} ) ;
414
428
415
429
You can’t perform that action at this time.
0 commit comments