mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 22:26:16 +03:00
Handle decoding events for form submissions with no buttons (no submitter).
This commit is contained in:
parent
e264ce3d07
commit
2a0c775462
@ -575,7 +575,6 @@ addItemForm =
|
||||
]
|
||||
description
|
||||
, formState.data |> Maybe.map (\error -> Html.div [ class "error", id "new-todo-error" ] [ text error ]) |> Maybe.withDefault (text "")
|
||||
, Html.button [ style "display" "none" ] [ Html.text "Create" ]
|
||||
]
|
||||
]
|
||||
}
|
||||
@ -600,7 +599,6 @@ editItemForm =
|
||||
, id ("todo-" ++ uuidToString formState.data.id)
|
||||
]
|
||||
description
|
||||
, Html.button [ style "display" "none" ] []
|
||||
]
|
||||
}
|
||||
)
|
||||
|
@ -27,13 +27,21 @@ formDataOnSubmit =
|
||||
]
|
||||
)
|
||||
)
|
||||
(Decode.at [ "submitter", "form", "method" ] methodDecoder)
|
||||
(Decode.at [ "submitter", "form", "action" ] Decode.string)
|
||||
(Decode.at [ "submitter", "form", "id" ] (Decode.nullable Decode.string))
|
||||
(currentForm "method" methodDecoder)
|
||||
(currentForm "action" Decode.string)
|
||||
(currentForm "id" (Decode.nullable Decode.string))
|
||||
|> Decode.map alwaysPreventDefault
|
||||
)
|
||||
|
||||
|
||||
currentForm : String -> Decode.Decoder a -> Decode.Decoder a
|
||||
currentForm field decoder_ =
|
||||
Decode.oneOf
|
||||
[ Decode.at [ "submitter", "form" ] decoder_
|
||||
, Decode.at [ "currentTarget", field ] decoder_
|
||||
]
|
||||
|
||||
|
||||
methodDecoder : Decode.Decoder FormData.Method
|
||||
methodDecoder =
|
||||
Decode.string
|
||||
|
Loading…
Reference in New Issue
Block a user