mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-28 22:37:08 +03:00
Fix initial value for checkbox event decoders.
This commit is contained in:
parent
5b92530e29
commit
116e9b775d
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user