Last active
December 17, 2015 20:05
-
-
Save fredcy/246863b4a884340f0d5c to your computer and use it in GitHub Desktop.
Elm onKeyPress event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Char | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import StartApp.Simple as StartApp | |
import String | |
main = | |
StartApp.start { model = model, view = view, update = update } | |
type alias Model = String | |
type alias Action = Int | |
model : Model | |
model = "foo" | |
view : Signal.Address Action -> String -> Html.Html | |
view address model = | |
div [] | |
[ input [ onKeyPress address identity ] [] | |
, div [] [ text model ] | |
] | |
update : Action -> Model -> Model | |
update action model = | |
case action |> Debug.log "action" of | |
_ -> model ++ (Char.fromCode action |> String.fromChar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment