From b35907abdafed8739a12853f7588140a81a007fd Mon Sep 17 00:00:00 2001 From: Ayrat Aminev Date: Tue, 17 Jun 2014 00:46:07 +0400 Subject: [PATCH] fix(NgModel): use string representation of the value in the ngMinlength and ngMaxlength Fixes #7848 --- src/ng/directive/input.js | 4 ++-- test/ng/directive/inputSpec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index fa6fe55d9f5e..d8ec82606555 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -2189,7 +2189,7 @@ var maxlengthDirective = function() { ctrl.$validate(); }); ctrl.$validators.maxlength = function(value) { - return ctrl.$isEmpty(value) || value.length <= maxlength; + return ctrl.$isEmpty(value) || value.toString().length <= maxlength; }; } }; @@ -2207,7 +2207,7 @@ var minlengthDirective = function() { ctrl.$validate(); }); ctrl.$validators.minlength = function(value) { - return ctrl.$isEmpty(value) || value.length >= minlength; + return ctrl.$isEmpty(value) || value.toString().length >= minlength; }; } }; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index e48a2a082672..bd315a522bbc 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1400,6 +1400,11 @@ describe('input', function() { changeInputValueTo('aaa'); expect(inputElm).toBeValid(); + + scope.$apply(function() { + scope.value = 1234; + }); + expect(inputElm).toBeValid(); }); it('should listen on ng-minlength when minlength is observed', function() { @@ -1446,6 +1451,11 @@ describe('input', function() { changeInputValueTo('aaa'); expect(inputElm).toBeValid(); + + scope.$apply(function() { + scope.value = 42; + }); + expect(inputElm).toBeValid(); }); it('should listen on ng-maxlength when maxlength is observed', function() {