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

Commit 694eb1a

Browse files
committed
fix(input): create max and/or min validation whatever the initial value is
1 parent d21dff2 commit 694eb1a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ng/directive/input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
12301230
return value;
12311231
});
12321232

1233-
if (attr.min || attr.ngMin) {
1233+
if (isDefined(attr.min) || attr.ngMin) {
12341234
var minVal;
12351235
ctrl.$validators.min = function(value) {
12361236
return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal;
@@ -1246,7 +1246,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
12461246
});
12471247
}
12481248

1249-
if (attr.max || attr.ngMax) {
1249+
if (isDefined(attr.max) || attr.ngMax) {
12501250
var maxVal;
12511251
ctrl.$validators.max = function(value) {
12521252
return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal;

test/ng/directive/inputSpec.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -4161,10 +4161,14 @@ describe('input', function() {
41614161
});
41624162

41634163
it('should validate even if min value changes on-the-fly', function() {
4164-
scope.min = 10;
4164+
scope.min = undefined;
41654165
compileInput('<input type="number" ng-model="value" name="alias" min="{{min}}" />');
4166+
expect(inputElm).toBeValid();
41664167

41674168
changeInputValueTo('15');
4169+
4170+
scope.min = 10;
4171+
scope.$digest();
41684172
expect(inputElm).toBeValid();
41694173

41704174
scope.min = 20;
@@ -4244,10 +4248,14 @@ describe('input', function() {
42444248
});
42454249

42464250
it('should validate even if max value changes on-the-fly', function() {
4247-
scope.max = 10;
4251+
scope.max = undefined;
42484252
compileInput('<input type="number" ng-model="value" name="alias" max="{{max}}" />');
4253+
expect(inputElm).toBeValid();
42494254

42504255
changeInputValueTo('5');
4256+
4257+
scope.max = 10;
4258+
scope.$digest();
42514259
expect(inputElm).toBeValid();
42524260

42534261
scope.max = 0;

0 commit comments

Comments
 (0)