From 0119423e9c9548d43da32c0e927d44fe0ff2176e Mon Sep 17 00:00:00 2001 From: Tommy Jonsson Date: Tue, 5 Nov 2013 13:33:38 +0100 Subject: [PATCH] fix(input): re-evaluate value if min/max changed --- src/ng/directive/input.js | 7 +++++++ test/ng/directive/inputSpec.js | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index da8825e34063..4da5f38bb7fe 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -541,6 +541,13 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { ctrl.$formatters.push(function(value) { return ctrl.$isEmpty(value) ? '' : '' + value; }); + + if (attr.min || attr.max) { + scope.$watch( + function() { return attr.min + '' + attr.max; }, + function() { ctrl.$setViewValue(ctrl.$viewValue); } + ); + } if (attr.min) { var minValidator = function(value) { diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 3783c9edcec7..7229e723ec50 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -735,19 +735,21 @@ describe('input', function() { expect(scope.form.alias.$error.min).toBeFalsy(); }); - it('should validate even if min value changes on-the-fly', function(done) { + it('should validate even if min value changes on-the-fly', function() { scope.min = 10; compileInput(''); scope.$digest(); changeInputValueTo('5'); expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); scope.min = 0; - scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); - }); + scope.$digest(); + expect(inputElm).toBeValid(); + expect(scope.value).toBe(5); + expect(scope.form.alias.$error.min).toBeFalsy(); }); }); @@ -769,19 +771,21 @@ describe('input', function() { expect(scope.form.alias.$error.max).toBeFalsy(); }); - it('should validate even if max value changes on-the-fly', function(done) { + it('should validate even if max value changes on-the-fly', function() { scope.max = 10; compileInput(''); scope.$digest(); changeInputValueTo('5'); expect(inputElm).toBeValid(); + expect(scope.value).toBe(5); + expect(scope.form.alias.$error.max).toBeFalsy(); scope.max = 0; - scope.$digest(function () { - expect(inputElm).toBeInvalid(); - done(); - }); + scope.$digest(); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.max).toBeTruthy(); }); });