-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathInput.elm
47 lines (34 loc) · 898 Bytes
/
Input.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
41
42
43
44
45
46
47
module Input exposing (Model, Msg(..), init, update, view)
{- This is an input module, which emits messages, when user types anything,
focuses on it, or when focus leaves the field.
-}
import Html exposing (Html, input)
import Html.Attributes exposing (type_, value)
import Html.Events exposing (onBlur, onFocus, onInput)
type alias Model =
String
init : Model -> ( Model, Cmd Msg )
init text =
( text, Cmd.none )
type Msg
= Update Model
| Focus
| Blur
view : Model -> Html Msg
view model =
input
[ type_ "text"
, onInput Update
, onFocus Focus
, onBlur Blur
, value model
]
[]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Update value ->
( value, Cmd.none )
-- Ignore the rest of the messages.
_ ->
( model, Cmd.none )