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

test(input): Minmaxlength databinding #5780

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {

// min length validator
if (attr.ngMinlength) {
var minlength = int(attr.ngMinlength);
var minLengthValidator = function(value) {
var minlength = int(attr.ngMinlength);
return validate(ctrl, 'minlength', ctrl.$isEmpty(value) || value.length >= minlength, value);
};

Expand All @@ -520,8 +520,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {

// max length validator
if (attr.ngMaxlength) {
var maxlength = int(attr.ngMaxlength);
var maxLengthValidator = function(value) {
var maxlength = int(attr.ngMaxlength);
return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) || value.length <= maxlength, value);
};

Expand Down
29 changes: 29 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,21 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});


it('should be updatable via binding', function(){
scope.boundLength = 3;
compileInput('<input type="text" ng-model="value" ng-minlength="{{boundLength}}" />');

changeInputValueTo('aaaa');
expect(scope.value).toBe('aaaa');

scope.boundLength = 6;
scope.$digest();
changeInputValueTo('aabb'); // TODO: this shouldn't need to changed to invalidate, but is (?)

expect(scope.value).toBeUndefined();
});
});


Expand All @@ -747,6 +762,20 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});


it('should be updatable via binding', function(){
scope.boundLength = 6;
compileInput('<input type="text" ng-model="value" ng-maxlength="{{boundLength}}" />');

changeInputValueTo('aaaa');
expect(scope.value).toBe('aaaa');

scope.boundLength = 3;
scope.$digest();
changeInputValueTo('aaab'); // TODO: this shouldn't need to changed to invalidate, but is (?)
expect(scope.value).toBeUndefined();
});
});


Expand Down