On Saturday, June 18, 2016 at 6:26:24 PM UTC-4, Dan P wrote: > 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. >
I think this is closely related to this longstanding issue: https://github.com/evancz/elm-html/issues/51 The problem is that Elm processes events like "input" asynchronously. After the browser fires the input event, some time is allowed to pass before the Elm runtime calls your update and view functions, and then some more time is allowed to pass before your new view is actually rendered to the DOM. Meanwhile, the browser has synchronously changed what is displayed in the input, so if you can't synchronously "undo" that change, the illegal input will be displayed briefly to the user. I'm not aware of any way to work around this issue within Elm, so long as it continues to processes events like "input" asynchronously. BTW, if anyone else wants to see this issue for themselves, here's a fully working example you can paste into http://elm-lang.org/try import Html exposing (Html, Attribute, text, div, input) import Html.App exposing (beginnerProgram) import Html.Attributes exposing (..) import Html.Events exposing (onInput) import String main = beginnerProgram { model = "", view = view, update = update } -- UPDATE type Msg = NewContent String update (NewContent content) oldContent = if (String.length content > 2) then oldContent else content -- VIEW view content = input [ type' "number", onInput NewContent, value content ] [] -- 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.
