attribute "onsubmit" "this.dispatchEvent(new Event('change')); return false;"
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/W3X_m1mE70w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
1. Sync all form inputs to the model as usual (e.g. if there's a text field, add an onKeyUp - or, even better, onInput - handler that uses targetValue to update the model with the string contents of the text field, then render that text field's value with the appropriate model data so it's always in sync with the model)
2. Add an onWithOptions submit handler to the form with { preventDefault = True } so it never causes a location change. (stopPropagation can stay False)
3. Perform validations on the form and display errors if validation failed.
4. If validations passed, then have that onWithOptions handler do one of the following things...
4a. Fire off an Http.post (or whatever you like) to send the model data directly to the server via AJAX.
4b. Update a *completely separate* <form> element with hidden inputs corresponding to the validated model data, then have a port trigger a manual form submission on that element. (From the end user's perspective, it's the same UX as if the original form had been submitted without stopPropagation.) We've used this technique in production and it works on browsers as far back as IE9.
Hope that helps!
import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes exposing (type')
import Json.Decode
view address model =
form
[ onWithOptions
"submit"
{ preventDefault = True, stopPropagation = False }
( Json.Decode.succeed Nothing )
(\_ -> Signal.message address { actionType = "SUBMIT", payload = "" })
]
[ button [ type' "submit" ] [ text "Submit" ] ]