diff --git a/examples/pokedex/app/Route/Form.elm b/examples/pokedex/app/Route/Form.elm index 3f22d098..e11c4dd6 100644 --- a/examples/pokedex/app/Route/Form.elm +++ b/examples/pokedex/app/Route/Form.elm @@ -275,6 +275,6 @@ view maybeUrl sharedModel static = [] [ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ] , form user - |> Form.toStatelessHtml Html.form (static.action |> Maybe.map .errors |> Maybe.withDefault (Form.init (form user))) + |> Form.toStatelessHtml Nothing Html.form (static.action |> Maybe.map .errors |> Maybe.withDefault (Form.init (form user))) ] } diff --git a/examples/pokedex/app/Route/Todos.elm b/examples/pokedex/app/Route/Todos.elm index 55387fad..17665667 100644 --- a/examples/pokedex/app/Route/Todos.elm +++ b/examples/pokedex/app/Route/Todos.elm @@ -271,6 +271,7 @@ view maybeUrl sharedModel model static = [ Html.text item.description , deleteItemForm item.id |> Form.toStatelessHtml + (Just (DeleteFormSubmitted item.id)) Html.form (Form.init (deleteItemForm item.id)) ] @@ -279,6 +280,7 @@ view maybeUrl sharedModel model static = , errorsView static.action , newItemForm model.submitting |> Form.toStatelessHtml + (Just FormSubmitted) Html.form (Form.init (newItemForm model.submitting)) ] diff --git a/src/Form.elm b/src/Form.elm index 4860ed78..ba2c0aef 100644 --- a/src/Form.elm +++ b/src/Form.elm @@ -1889,18 +1889,24 @@ performing a client-side submit onSubmit (usually with Effect.Perform). -} toStatelessHtml : - (List (Html.Attribute (Pages.Msg.Msg msg)) -> List view -> view) + Maybe (List ( String, String ) -> msg) + -> (List (Html.Attribute (Pages.Msg.Msg msg)) -> List view -> view) -> Model -> Form (Pages.Msg.Msg msg) String value view -> view -toStatelessHtml toForm serverValidationErrors (Form fields _ _ _ config) = +toStatelessHtml customOnSubmit toForm serverValidationErrors (Form fields _ _ _ config) = toForm -- TODO get method from config [ config.method |> Maybe.withDefault "POST" |> Attr.method , Attr.novalidate True - , Pages.Msg.onSubmit + , customOnSubmit + |> Maybe.map + (\onSubmit -> + FormDecoder.formDataOnSubmit |> Attr.map (onSubmit >> Pages.Msg.UserMsg) + ) + |> Maybe.withDefault Pages.Msg.onSubmit ] (renderedFields Nothing serverValidationErrors fields)