Skip to content

Instantly share code, notes, and snippets.

@fredcy
Created December 21, 2015 21:10
Show Gist options
  • Save fredcy/bac816646c1ff55853e1 to your computer and use it in GitHub Desktop.
Save fredcy/bac816646c1ff55853e1 to your computer and use it in GitHub Desktop.
Elm example of Html.Attributes.selected problem
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import StartApp.Simple as StartApp
options : List (String)
options = [ "one", "two", "three", "four", "five" ]
type alias Model = String
type alias Action = String
optionList : Model -> List (Html)
optionList m =
let
makeOption t =
option [ value t
, selected (t == m)
]
[ text t ]
in
List.map makeOption options
view : Signal.Address Action -> Model -> Html
view addr m =
div [ value m
, on "change" targetValue <| Signal.message addr
]
[ select [] (optionList m)
, div [] [ text m ]
]
{- Update, but do not allow one of the options to take effect.
-}
update : Action -> Model -> Model
update a m =
case a |> Debug.log "action" of
"three" -> m
_ -> a
main : Signal Html
main =
StartApp.start
{ model = "two"
, view = view
, update = update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment