Handle decoding events for form submissions with no buttons (no submitter).

This commit is contained in:
Dillon Kearns 2022-09-06 09:47:37 -07:00
parent e264ce3d07
commit 2a0c775462
2 changed files with 11 additions and 5 deletions

View File

@ -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" ] []
]
}
)

View File

@ -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