Fix initial value for checkbox event decoders.

This commit is contained in:
Dillon Kearns 2022-06-16 08:40:44 -07:00
parent 5b92530e29
commit 116e9b775d

View File

@ -35,12 +35,35 @@ type alias FieldEvent =
fieldEventDecoder : Decoder FieldEvent fieldEventDecoder : Decoder FieldEvent
fieldEventDecoder = fieldEventDecoder =
Decode.map4 FieldEvent Decode.map4 FieldEvent
(Decode.at [ "target", "value" ] Decode.string) inputValueDecoder
(Decode.at [ "currentTarget", "id" ] Decode.string) (Decode.at [ "currentTarget", "id" ] Decode.string)
(Decode.at [ "target", "name" ] Decode.string) (Decode.at [ "target", "name" ] Decode.string)
fieldDecoder fieldDecoder
inputValueDecoder : Decoder String
inputValueDecoder =
Decode.at [ "target", "type" ] Decode.string
|> Decode.andThen
(\targetType ->
case targetType of
"checkbox" ->
Decode.map2
(\valueWhenChecked isChecked ->
if isChecked then
valueWhenChecked
else
""
)
(Decode.at [ "target", "value" ] Decode.string)
(Decode.at [ "target", "checked" ] Decode.bool)
_ ->
Decode.at [ "target", "value" ] Decode.string
)
fieldDecoder : Decoder Event fieldDecoder : Decoder Event
fieldDecoder = fieldDecoder =
Decode.field "type" Decode.string Decode.field "type" Decode.string
@ -48,29 +71,7 @@ fieldDecoder =
(\type_ -> (\type_ ->
case type_ of case type_ of
"input" -> "input" ->
Decode.at [ "target", "type" ] Decode.string inputValueDecoder |> Decode.map InputEvent
|> Decode.andThen
(\targetType ->
case targetType of
"checkbox" ->
Decode.map2
(\valueWhenChecked isChecked ->
(if isChecked then
valueWhenChecked
else
""
)
|> InputEvent
)
(Decode.at [ "target", "value" ] Decode.string)
(Decode.at [ "target", "checked" ] Decode.bool)
_ ->
Decode.map
InputEvent
(Decode.at [ "target", "value" ] Decode.string)
)
"focusin" -> "focusin" ->
FocusEvent FocusEvent