Skip to content

Instantly share code, notes, and snippets.

@benthepoet
Created June 6, 2018 20:00
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 benthepoet/a32ad88e08666b4640ae0c4fc8a4a937 to your computer and use it in GitHub Desktop.
Save benthepoet/a32ad88e08666b4640ae0c4fc8a4a937 to your computer and use it in GitHub Desktop.
Ctrl-Enter Form Event
module Main exposing (main)
import Html exposing (Html)
import Html.Events as Events
import Json.Decode as Decode
type alias KeyUpEvent =
{ ctrlKey : Bool
, key : String
}
eventDecoder =
Decode.map2 Event
(Decode.field "ctrlKey" Decode.bool)
(Decode.field "key" Decode.string)
onKeyUp =
Events.on "keyup" eventDecoder
model = ""
type Msg
= Event Bool String
update msg model =
case msg of
Event ctrlKey key ->
toString <| ctrlKey && key == "Enter"
main =
Html.beginnerProgram
{ model = model
, update = update
, view = view
}
view model =
Html.form
[ onKeyUp ]
[ Html.textarea [] []
, Html.div [] [ Html.text model ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment