The handler onClickdoes not work with elements option. Instead, you want to capture the event changeand look at JSON targetValueto see what was selected.
onClick option tag value:
viewOption : Role -> Html Msg
viewOption role =
option
[ value <| toString role ]
[ text <| toString role ]
JSON, targetValue Role:
targetValueRoleDecoder : Json.Decode.Decoder Role
targetValueRoleDecoder =
targetValue `Json.Decode.andThen` \val ->
case val of
"Admin" -> Json.Decode.succeed Admin
"User" -> Json.Decode.succeed User
"None" -> Json.Decode.succeed None
_ -> Json.Decode.fail ("Invalid Role: " ++ val)
select change:
[ select
[ on "change" (Json.Decode.map SelectRole targetValueRoleDecoder)
]
[ viewOption None
, viewOption Admin
, viewOption User
]
, , DOM . Role ; JSON-, , Elm String to Union Type.