diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js
index cb432c52a5c7..59250d755cf1 100644
--- a/src/ng/directive/input.js
+++ b/src/ng/directive/input.js
@@ -998,7 +998,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.ngMinlength) {
var minlength = int(attr.ngMinlength);
var minLengthValidator = function(value) {
- return validate(ctrl, 'minlength', ctrl.$isEmpty(value) || value.length >= minlength, value);
+ return validate(ctrl, 'minlength', ctrl.$isEmpty(value) ||
+ (!isDefined(value.length) || value.length >= minlength), value);
};
ctrl.$parsers.push(minLengthValidator);
@@ -1009,7 +1010,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.ngMaxlength) {
var maxlength = int(attr.ngMaxlength);
var maxLengthValidator = function(value) {
- return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) || value.length <= maxlength, value);
+ return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) ||
+ (!isDefined(value.length) || value.length <= maxlength), value);
};
ctrl.$parsers.push(maxLengthValidator);
diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js
index eba3028e7bce..725f0c33ac3a 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -744,6 +744,34 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});
+
+
+ it('should invalidate model values shorter than given minlength', function() {
+ compileInput('');
+
+ scope.$apply(function() {
+ scope.value = "1234";
+ });
+
+ expect(inputElm).toBeInvalid();
+
+ scope.$apply(function() {
+ scope.value = "123456789";
+ });
+
+ expect(inputElm).toBeValid();
+ });
+
+
+ it('should not invalidate model-values which are not string-like or array-like', function() {
+ compileInput('');
+
+ scope.$apply(function() {
+ scope.value = 10;
+ });
+
+ expect(inputElm).toBeValid();
+ });
});
@@ -758,6 +786,34 @@ describe('input', function() {
changeInputValueTo('aaa');
expect(scope.value).toBe('aaa');
});
+
+
+ it('should invalidate model values longer than given maxlength', function() {
+ compileInput('');
+
+ scope.$apply(function() {
+ scope.value = "123456789";
+ });
+
+ expect(inputElm).toBeInvalid();
+
+ scope.$apply(function() {
+ scope.value = "1234";
+ });
+
+ expect(inputElm).toBeValid();
+ });
+
+
+ it('should not invalidate model-values which are not string-like or array-like', function() {
+ compileInput('');
+
+ scope.$apply(function() {
+ scope.value = 1000;
+ });
+
+ expect(inputElm).toBeValid();
+ });
});