Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number input with 0.01 steps gives undefined for certain values in angularjs

With a input of that type in angularjs (1.6.1) gives undefined for values between 9.03 to 9.05 inclusively. The problem reproduces with other values, among others 9.62, 9.63, 17.31.

<input type="number" step="0.01" data-ng-model="$ctrl.numericValue" />

This fiddle reproduces the problem. Just click up in the numeric input.

Tested on firefox and chromium under linux mint 18.

It seems linked to the "step" attribute. If it is set to "0.001" there's no problem. But I threat money in this application, so 2 decimal is needed.

Note : if value is initially set to 9.03 via data-numeric-value, it is not undefined.

Any workaround for this bug ?

edit

updated fiddle to show behavior whit step="0.01" versus step="0.001"

edit 2 I made a plunkr while filling the bug report, to find that the bug is corrected in the "snapshot" version, witch is 1.6.2. But this version is not available for download via the angularjs site for the moment.

like image 378
Johnny5 Avatar asked Jan 11 '17 14:01

Johnny5


1 Answers

It seems to be a bug in Angular. Using Angular 1.6.0, the same issue happens. If you use Angular 1.5.9, it seems to work fine. Something between those two versions has caused this issue and it has not been found or resolved in 1.6.1 yet.

So the best course of action is to raise a bug with the Angular team.

A short term solution for your own project would be to roll back to Angular 1.5.9 if possible.

I've tested it on Windows 7 on both Firefox and Chrome to get these results.

like image 54
René Wolferink Avatar answered Nov 20 '22 12:11

René Wolferink