Created
August 31, 2017 03:53
-
-
Save ksunair/59cd0ac4f7bf7ac24971da200bb554a3 to your computer and use it in GitHub Desktop.
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 (..) | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import Debug exposing (..) | |
type alias Model = | |
{ fullName : String | |
, firstName : String | |
, lastName : String | |
} | |
initData : Model | |
initData = | |
{ fullName = "" | |
, firstName = "" | |
, lastName = "" | |
} | |
type Msg | |
= Add | |
| Clear | |
| InputFN String | |
| InputLN String | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Add -> | |
{ model | |
| fullName = (log "first name : " model.firstName) ++ (log "last name : " model.lastName) | |
, firstName = "" | |
, lastName = "" | |
} | |
Clear -> | |
initData | |
InputFN str -> | |
{ model | |
| firstName = str | |
} | |
InputLN str -> | |
{ model | |
| lastName = str | |
} | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ h3 [] [ text ("Full Name : " ++ model.fullName) ] | |
, input [ onInput InputFN ] [] | |
, input [ onInput InputLN ] [] | |
, button [ onClick Add ] [ text "FullName" ] | |
, button [ onClick Clear ] [ text "Clear" ] | |
] | |
main = | |
beginnerProgram { model = initData, view = view, update = update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment