Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

In chrome generating type=number without step attribute does not allow decimal values. #2712

Closed
sornaks opened this issue Jun 17, 2015 · 3 comments
Assignees
Milestone

Comments

@sornaks
Copy link

sornaks commented Jun 17, 2015

When using Html.EditorFor() if the model is of type float or double we generate a input tag with type=number. Chrome does not allow decimal values in input tags of type number unless a step attribute is specified - https://code.google.com/p/chromium/issues/detail?id=74120. From the link:

According to the standard, a number with a fractional part such as 97.2 is invalid if step= attribute is not specified.

We do not generate that step attribute. We should add step=any to get it working.

However, IE allows decimal values without adding step attribute.

@danroth27 danroth27 added this to the 6.0.0-beta6 milestone Jun 18, 2015
@ghost
Copy link

ghost commented Jun 25, 2015

That is an old issue (2011). Not sure if it still holds the candle as on latest Chrome (v43.0.2357.130), it accepts the decimal without step, as default value of step in IE, Chrome and Firefox is null.

However, the behavior is reproducible in IE11.

<!doctype html>
<html>

    <body>
        <form type="post" action="https://github.com/">
            <input type="number" value="97.2" />
            <input type="submit" />
        </form>
        <script>
            var element = document.querySelector("[type=number]")

            alert
            (
                "default value of step: " + element.getAttribute("step") +
                "\nvalue: " + element.value +
                "\nFails validation on submit in IE11"
            )
        </script>
    </body>

</html>

At this point I am not sure which browser is actually conforming with the standard here, but the step (with decimal like 0.3) is required in IE11.

Try entering an alphabet to trigger the real validation error on all Firefox, IE and Chrome.

@ctolkien
Copy link

In EN-AU culture:

<input type="number" value="1.5" />

Will not submit in either IE11 or Chrome 43.

http://codepen.io/anon/pen/mJLNvO

Edit: Actually, the above isn't correct.

Chrome:

If you have no step attribute, but an initial value that is a float (as above), then it will accept a float. If you have no step and no value, or an integer based value, it will not accept a float value.

FF appears to act the same.

IE11 will not accept floats unless a step value is supplied.

@ajaybhargavb
Copy link
Contributor

Spoke to @dougbu and @NTaylorMullen, we decided to use type=text for float and double types. This also maintains consistency with MVC 5 behavior. Closing this issue as this is no longer relevant.

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

No branches or pull requests

4 participants