From af02d90e878ffc81a972f52a0113ce2002ed0cc2 Mon Sep 17 00:00:00 2001 From: Ayrat Aminev Date: Tue, 17 Jun 2014 00:23:35 +0400 Subject: [PATCH] fix(NgModel): use string representation of the value in the ngMinlength and ngMaxlength --- src/ng/directive/input.js | 4 ++-- test/ng/directive/inputSpec.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 7b0412bd80e8..2f39fc60214c 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -584,7 +584,7 @@ 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) || value.toString().length >= minlength, value); }; ctrl.$parsers.push(minLengthValidator); @@ -595,7 +595,7 @@ 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) || value.toString().length <= maxlength, value); }; ctrl.$parsers.push(maxLengthValidator); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index d14e1a2601c0..b67ada993091 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -761,6 +761,16 @@ describe('input', function() { changeInputValueTo('aaa'); expect(scope.value).toBe('aaa'); }); + + it('should use string representation of the value', function(){ + compileInput(''); + + scope.$apply(function() { + scope.value = 123; + }); + + expect(inputElm).toBeValid(); + }); }); @@ -775,6 +785,16 @@ describe('input', function() { changeInputValueTo('aaa'); expect(scope.value).toBe('aaa'); }); + + it('should use string representation of the value', function(){ + compileInput(''); + + scope.$apply(function() { + scope.value = 123; + }); + + expect(inputElm).toBeValid(); + }); });