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

fix(input): fix step validation for input[number]/input[range] #15264

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ function countDecimals(num) {

if (decimalSymbolIndex === -1) {
if (-1 < num && num < 1) {
// It may be in the exponentional notation format (`1e-X`)
// It may be in the exponential notation format (`1e-X`)
var match = /e-(\d+)$/.exec(numString);

if (match) {
Expand Down
6 changes: 4 additions & 2 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,8 @@ describe('input', function() {
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(8);

$rootScope.$apply('min = 10; step = 20; value = 30');
$rootScope.$apply('min = 10; step = 20');
helper.changeInputValueTo('30');
expect(inputElm.val()).toBe('30');
expect(inputElm).toBeValid();
expect($rootScope.value).toBe(30);
Expand All @@ -2748,7 +2749,8 @@ describe('input', function() {
expect($rootScope.value).toBe(30);

// 0.3 - 0.2 === 0.09999999999999998
$rootScope.$apply('min = 0.2; step = 0.09999999999999998; value = 0.3');
$rootScope.$apply('min = 0.2; step = (0.3 - 0.2)');
helper.changeInputValueTo('0.3');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing the scope value (e.g. $rootScope.$apply('value = '0.3')), because ngModel does not overwrite programmatically changed scope values unless the validity of the input changes. Depending on the order in which the validators are run and the previous state, this may lead to the scope value remaining 0.3 instead of being set to undefined.

expect(inputElm.val()).toBe('0.3');
expect(inputElm).toBeInvalid();
expect(ngModel.$error.step).toBe(true);
Expand Down