Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit bfcf994

Browse files
committed
fix(validators): maxlength should use viewValue for $isEmpty
Closes #10898
1 parent b462f5d commit bfcf994

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/ng/directive/validators.js

+1-1
Original file line numberDiff line numberDiff 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
};

test/ng/directive/validatorsSpec.js

+14
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)