mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 12:52:27 +03:00
Allow custom onsubmit in stateless form.
This commit is contained in:
parent
6f6db5c1bf
commit
2be5d1c07e
@ -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)))
|
||||
]
|
||||
}
|
||||
|
@ -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))
|
||||
]
|
||||
|
12
src/Form.elm
12
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user