Skip to content

Instantly share code, notes, and snippets.

@rebelwarrior
Created February 12, 2018 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebelwarrior/08f2fee4068ffb8c7209c25402f25f07 to your computer and use it in GitHub Desktop.
Save rebelwarrior/08f2fee4068ffb8c7209c25402f25f07 to your computer and use it in GitHub Desktop.
SlightlyLessSimpleDropdown.elm
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (on, targetValue)
import Json.Decode
main =
beginnerProgram { model = "", view = view, update = update }
view model =
div []
[ select [ on "change" valueDecoder ]
[ option [value "strawberry" ] [ text "strawberry" ]
, option [value "chocolate" ] [ text "chocolate" ]
, option [value "vanilla" ] [ text "vanilla" ]
]
, div [] [ text (model) ]
]
update msg model =
toString msg
flavorToUpcase value =
value
|> String.toUpper
|> Json.Decode.succeed
valueDecoder =
Html.Events.targetValue
|> Json.Decode.andThen flavorToUpcase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment