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

fix(input): fix step validation for input[type=number/range] #15506

Closed
wants to merge 2 commits into from

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Dec 13, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
The validation will incorrectly fail in certain cases (e.g. step: 0.01, value: 1.16 or 20.1), due to Floating Point Arithmetic limitations. The previous fix for FPA limitations (081d06f) tried to solve the issue by converting the numbers to integers, before doing the actual calculation, but it failed to account for cases where the conversion itself returned non-integer values (again due to FPA limitations).
See also #15504.

What is the new behavior (if this is a feature change)?
The validation works correctly by ensuring that the values used in the final calculation are always integers.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

Other information:
Fixes #15504.

Previously, the validation would incorrectly fail in certain cases (e.g.
`step: 0.01`, `value: 1.16 or 20.1`), due to Floating Point Arithmetic
limitations. The previous fix for FPA limitations (081d06f) tried to solve the
issue by converting the numbers to integers, before doing the actual
calculation, but it failed to account for cases where the conversion itself
returned non-integer values (again due to FPA limitations).
This commit fixes it by ensuring that the values used in the final calculation
are always integers.

Fixes angular#15504
@Narretz
Copy link
Contributor

Narretz commented Dec 15, 2016

Looks like IE9 doesn't like the fix:

IE 9.0.0 (Windows 7 0.0.0) input range step should correctly validate even in cases where the JS floating point arithmetic fails FAILED

	Expected to have ng-valid and not have ng-invalid but had ng-untouched ng-not-empty ng-dirty ng-valid-number ng-invalid ng-inv

@gkalpak gkalpak modified the milestones: 1.5.10, 1.5.11 Dec 15, 2016
@gkalpak
Copy link
Member Author

gkalpak commented Dec 15, 2016

For the first time in a long time, IE9 was right and I was wrong 😃
PTAL

@Narretz
Copy link
Contributor

Narretz commented Dec 28, 2016

LGTM

@gkalpak gkalpak closed this in a24777a Dec 29, 2016
gkalpak added a commit that referenced this pull request Dec 29, 2016
Previously, the validation would incorrectly fail in certain cases (e.g.
`step: 0.01`, `value: 1.16 or 20.1`), due to Floating Point Arithmetic
limitations. The previous fix for FPA limitations (081d06f) tried to solve the
issue by converting the numbers to integers, before doing the actual
calculation, but it failed to account for cases where the conversion itself
returned non-integer values (again due to FPA limitations).
This commit fixes it by ensuring that the values used in the final calculation
are always integers.

Fixes #15504

Closes #15506
@gkalpak gkalpak deleted the fix-input-step-validation branch January 3, 2017 17:29
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
Previously, the validation would incorrectly fail in certain cases (e.g.
`step: 0.01`, `value: 1.16 or 20.1`), due to Floating Point Arithmetic
limitations. The previous fix for FPA limitations (081d06f) tried to solve the
issue by converting the numbers to integers, before doing the actual
calculation, but it failed to account for cases where the conversion itself
returned non-integer values (again due to FPA limitations).
This commit fixes it by ensuring that the values used in the final calculation
are always integers.

Fixes angular#15504

Closes angular#15506
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken ngStep for input[type="number"] directive
3 participants