forked from mattjbray/servant-elm-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.elm
40 lines (29 loc) · 839 Bytes
/
Events.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Events (onChange, onEnter, onSubmitPreventDefault) where
{-| Extensions to the Html.Events library.
@docs onEnter
-}
import Html exposing (Attribute)
import Html.Events exposing (..)
import Json.Decode as Json
import Signal exposing (..)
onEnter : Address a -> a -> Attribute
onEnter address value =
on
"keydown"
(Json.customDecoder keyCode is13)
(\_ -> Signal.message address value)
is13 : Int -> Result String ()
is13 code =
if code == 13 then
Ok ()
else
Err "not the right key code"
onChange : Address a -> (String -> a) -> Html.Attribute
onChange address f =
on "input" targetValue (message (forwardTo address f))
onSubmitPreventDefault address message =
onWithOptions
"submit"
{ defaultOptions | preventDefault = True }
Json.value
(\_ -> Signal.message address message)