File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ var maxlengthDirective = function() {
6565 ctrl . $validate ( ) ;
6666 } ) ;
6767 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 ) ;
6969 } ;
7070 }
7171 } ;
Original file line number Diff line number Diff line change @@ -410,6 +410,20 @@ describe('validators', function() {
410410 expect ( $rootScope . value ) . toBe ( 12345 ) ;
411411 expect ( $rootScope . form . input . $error . maxlength ) . toBeUndefined ( ) ;
412412 } ) ;
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+ } ) ;
413427 } ) ;
414428
415429
You can’t perform that action at this time.
0 commit comments