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

Commit ad3ec3d

Browse files
committed
remove tests for changing step value
1 parent 8f3daa2 commit ad3ec3d

File tree

2 files changed

+26
-55
lines changed

2 files changed

+26
-55
lines changed

Diff for: src/ng/directive/input.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1610,15 +1610,24 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16101610
if (stepAttributeType) {
16111611
ctrl.$validators.step = stepAttributeType === 'step' && supportsRange ?
16121612
function noopStepValidator() {
1613-
// Since all browsers set the input to a valid value, we don't need to check validity
1614-
return true;
1613+
// Currently, only FF implements the spec on step change correctly (i.e. adjusting the
1614+
// input element value to a valid value). Other browsers have various problems, such as
1615+
// setting the stepMismatch error instead
1616+
return !validity.stepMismatch;
16151617
} :
16161618
// ngStep doesn't set the setp attr, so the browser doesn't adjust the input value as setting step would
16171619
function stepValidator(modelValue, viewValue) {
16181620
return ctrl.$isEmpty(viewValue) || isUndefined(stepVal) || viewValue % stepVal === 0;
16191621
};
16201622

1621-
// Assign stepVal when the directive is linked. This won't run the validators as the model isn't ready yet
1623+
if (stepAttributeType === 'step') {
1624+
// Set the actual element attribute so that the browser can adjust the value based on
1625+
// the max value, which might be interpolated
1626+
element.attr('step', attr.step);
1627+
}
1628+
1629+
// This initalizes the step value, so that non-support browsers validate with the correct
1630+
// values during the initial $render
16221631
stepChange(attr.step);
16231632
attr.$observe('step', stepChange);
16241633
}
@@ -1675,7 +1684,7 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16751684
if (isDefined(val) && !isNumber(val)) {
16761685
val = parseFloat(val);
16771686
}
1678-
stepVal = isNumber(val) && !isNaN(val) ? val : undefined;
1687+
stepVal = isNumber(val) && !isNaN(val) ? val : 1;
16791688
// ignore changes before model is initialized
16801689
if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) {
16811690
return;

Diff for: test/ng/directive/inputSpec.js

+13-51
Original file line numberDiff line numberDiff line change
@@ -3310,76 +3310,37 @@ describe('input', function() {
33103310
expect(scope.form.alias.$error.step).toBeFalsy();
33113311
});
33123312

3313-
it('should adjust the element and model value if the step value changes on-the-fly', function() {
3314-
scope.step = 10;
3315-
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" step="{{step}}" />');
3316-
3317-
helper.changeInputValueTo('5');
3318-
expect(inputElm).toBeValid();
3319-
expect(scope.value).toBe(10);
3320-
3321-
// Step changes, but value matches
3322-
scope.$apply('step = 5');
3323-
expect(inputElm).toBeValid();
3324-
expect(scope.value).toBe(10);
3325-
expect(inputElm.val()).toBe('10');
3326-
3327-
// Step changes, value does not match
3328-
scope.$apply('step = 6');
3329-
expect(inputElm).toBeValid();
3330-
expect(scope.value).toBe(12);
3331-
expect(inputElm.val()).toBe('12');
3332-
3333-
// null is ignored
3334-
scope.$apply('step = null');
3335-
expect(inputElm).toBeValid();
3336-
expect(scope.value).toBe(12);
3337-
expect(inputElm.val()).toBe('12');
3338-
3339-
// Step val as string
3340-
scope.$apply('step = "7"');
3341-
expect(inputElm).toBeValid();
3342-
expect(scope.value).toBe(14);
3343-
expect(inputElm.val()).toBe('14');
3344-
3345-
// unparsable string is ignored
3346-
scope.step = 'abc';
3347-
scope.$digest();
3348-
expect(inputElm).toBeValid();
3349-
expect(scope.value).toBe(14);
3350-
expect(inputElm.val()).toBe('14');
3351-
});
3352-
33533313
} else {
33543314
it('should validate if "range" is not implemented', function() {
3355-
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" step="10" />');
3315+
scope.step = 10;
3316+
scope.value = 20;
3317+
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" step="{{step}}" />');
33563318

3357-
scope.$apply('value = 20');
3358-
expect(inputElm.val()).to('20');
3319+
expect(inputElm.val()).toBe('20');
33593320
expect(inputElm).toBeValid();
33603321
expect(scope.value).toBe(20);
33613322
expect(scope.form.alias.$error.step).toBeFalsy();
33623323

33633324
helper.changeInputValueTo('18');
33643325
expect(inputElm).toBeInvalid();
3365-
expect(inputElm.val()).to('18');
3326+
expect(inputElm.val()).toBe('18');
33663327
expect(scope.value).toBeUndefined();
33673328
expect(scope.form.alias.$error.step).toBeTruthy();
33683329

33693330
helper.changeInputValueTo('10');
33703331
expect(inputElm).toBeValid();
3371-
expect(inputElm.val()).to('10');
3332+
expect(inputElm.val()).toBe('10');
33723333
expect(scope.value).toBe(10);
33733334
expect(scope.form.alias.$error.step).toBeFalsy();
33743335

33753336
scope.$apply('value = 12');
33763337
expect(inputElm).toBeInvalid();
3377-
expect(inputElm.val()).to('12');
3338+
expect(inputElm.val()).toBe('12');
33783339
expect(scope.value).toBe(12);
33793340
expect(scope.form.alias.$error.step).toBeTruthy();
33803341
});
33813342

3382-
it('should validate even if the max value changes on-the-fly', function() {
3343+
it('should validate even if the step value changes on-the-fly', function() {
33833344
scope.step = 10;
33843345
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" step="{{step}}" />');
33853346

@@ -3391,13 +3352,13 @@ describe('input', function() {
33913352
scope.$apply('step = 5');
33923353
expect(inputElm.val()).toBe('10');
33933354
expect(inputElm).toBeValid();
3394-
expect(scope.value).toBeUndefined();
3355+
expect(scope.value).toBe(10);
33953356
expect(scope.form.alias.$error.step).toBeFalsy();
33963357

33973358
// Step changes, value does not match
33983359
scope.$apply('step = 6');
33993360
expect(inputElm).toBeInvalid();
3400-
expect(scope.value).toBe(10);
3361+
expect(scope.value).toBeUndefined();
34013362
expect(inputElm.val()).toBe('10');
34023363
expect(scope.form.alias.$error.step).toBeTruthy();
34033364

@@ -3428,9 +3389,10 @@ describe('input', function() {
34283389
describe('ngStep', function() {
34293390

34303391
it('should validate', function() {
3431-
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" ng-step="5" />');
3392+
scope.step = 5;
3393+
scope.value = 5;
3394+
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" ng-step="step" />');
34323395

3433-
scope.$apply('value = 5');
34343396
expect(inputElm).toBeValid();
34353397
expect(inputElm.val()).toBe('5');
34363398
expect(scope.value).toBe(5);

0 commit comments

Comments
 (0)