Hi all, Elm newbie here. I'm trying to emulate the HTML input maxlength
<http://package.elm-lang.org/packages/elm-lang/html/1.0.0/Html-Attributes#maxlength>
attribute
when type="number", in order to input an hour of the day. Using vanilla JS
I would do the following:
*index.html*
<html><body>
<input id="el" type="number">
</body></html>
*main.js*
oldvalue = ""
// The value of the element is already set before this function gets called.
document.getElementById("el").oninput = function (e) {
if (e.target.value.length > 2)
e.target.value = oldvalue;
else
oldvalue = e.target.value;
}
However when I write this in Elm using onInput, the user's invalid input is
visible for a few milliseconds before being fixed. To me this seems like a
vDOM issue, but I really don't know.
*Main.elm*
model = ""
update (Input s) model = if (String.length s > 2) then model else s
view model = [ input [ type "number", onInput Input, value model ] [] ]
I've combed through all the documentation in the Html package, and found
nothing that would address this. My idea would be to somehow embed ordinary
HTML inside my application (the guide does the inverse
<http://guide.elm-lang.org/interop/html.html> of this), but I don't know
how to do that either : /
Thanks for your help!
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.