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

Commit d289968

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 facfec9 commit d289968

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-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

+24-4
Original file line numberDiff line numberDiff line change
@@ -4211,12 +4211,17 @@ describe('input', function() {
42114211
});
42124212

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

42174218
changeInputValueTo('15');
42184219
expect(inputElm).toBeValid();
42194220

4221+
scope.min = 10;
4222+
scope.$digest();
4223+
expect(inputElm).toBeValid();
4224+
42204225
scope.min = 20;
42214226
scope.$digest();
42224227
expect(inputElm).toBeInvalid();
@@ -4252,12 +4257,17 @@ describe('input', function() {
42524257
});
42534258

42544259
it('should validate even if the ngMin value changes on-the-fly', function() {
4255-
scope.min = 10;
4260+
scope.min = undefined;
42564261
compileInput('<input type="number" ng-model="value" name="alias" ng-min="min" />');
4262+
expect(inputElm).toBeValid();
42574263

42584264
changeInputValueTo('15');
42594265
expect(inputElm).toBeValid();
42604266

4267+
scope.min = 10;
4268+
scope.$digest();
4269+
expect(inputElm).toBeValid();
4270+
42614271
scope.min = 20;
42624272
scope.$digest();
42634273
expect(inputElm).toBeInvalid();
@@ -4294,12 +4304,17 @@ describe('input', function() {
42944304
});
42954305

42964306
it('should validate even if max value changes on-the-fly', function() {
4297-
scope.max = 10;
4307+
scope.max = undefined;
42984308
compileInput('<input type="number" ng-model="value" name="alias" max="{{max}}" />');
4309+
expect(inputElm).toBeValid();
42994310

43004311
changeInputValueTo('5');
43014312
expect(inputElm).toBeValid();
43024313

4314+
scope.max = 10;
4315+
scope.$digest();
4316+
expect(inputElm).toBeValid();
4317+
43034318
scope.max = 0;
43044319
scope.$digest();
43054320
expect(inputElm).toBeInvalid();
@@ -4335,12 +4350,17 @@ describe('input', function() {
43354350
});
43364351

43374352
it('should validate even if the ngMax value changes on-the-fly', function() {
4338-
scope.max = 10;
4353+
scope.max = undefined;
43394354
compileInput('<input type="number" ng-model="value" name="alias" ng-max="max" />');
4355+
expect(inputElm).toBeValid();
43404356

43414357
changeInputValueTo('5');
43424358
expect(inputElm).toBeValid();
43434359

4360+
scope.max = 10;
4361+
scope.$digest();
4362+
expect(inputElm).toBeValid();
4363+
43444364
scope.max = 0;
43454365
scope.$digest();
43464366
expect(inputElm).toBeInvalid();

0 commit comments

Comments
 (0)