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

Commit 8e3c0cd

Browse files
committed
fix(input): create max and/or min validation whatever the initial value is
- fix issue #10307 - change tests to corresponding changes - also change tests for ngmax and ngmin (though they have no some issue) Closes #10307
1 parent f2e7f87 commit 8e3c0cd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
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

+20-4
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;
@@ -4202,10 +4206,14 @@ describe('input', function() {
42024206
});
42034207

42044208
it('should validate even if the ngMin value changes on-the-fly', function() {
4205-
scope.min = 10;
4209+
scope.min = undefined;
42064210
compileInput('<input type="number" ng-model="value" name="alias" ng-min="min" />');
4211+
expect(inputElm).toBeValid();
42074212

42084213
changeInputValueTo('15');
4214+
4215+
scope.min = 10;
4216+
scope.$digest();
42094217
expect(inputElm).toBeValid();
42104218

42114219
scope.min = 20;
@@ -4244,10 +4252,14 @@ describe('input', function() {
42444252
});
42454253

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

42504259
changeInputValueTo('5');
4260+
4261+
scope.max = 10;
4262+
scope.$digest();
42514263
expect(inputElm).toBeValid();
42524264

42534265
scope.max = 0;
@@ -4285,10 +4297,14 @@ describe('input', function() {
42854297
});
42864298

42874299
it('should validate even if the ngMax value changes on-the-fly', function() {
4288-
scope.max = 10;
4300+
scope.max = undefined;
42894301
compileInput('<input type="number" ng-model="value" name="alias" ng-max="max" />');
4302+
expect(inputElm).toBeValid();
42904303

42914304
changeInputValueTo('5');
4305+
4306+
scope.max = 10;
4307+
scope.$digest();
42924308
expect(inputElm).toBeValid();
42934309

42944310
scope.max = 0;

0 commit comments

Comments
 (0)