Created
June 6, 2018 20:00
-
-
Save benthepoet/a32ad88e08666b4640ae0c4fc8a4a937 to your computer and use it in GitHub Desktop.
Ctrl-Enter Form 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
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