Skip to content

Instantly share code, notes, and snippets.

@fredcy
Last active December 17, 2015 20:05
Show Gist options
  • Save fredcy/246863b4a884340f0d5c to your computer and use it in GitHub Desktop.
Save fredcy/246863b4a884340f0d5c to your computer and use it in GitHub Desktop.
Elm onKeyPress event
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