Created
August 31, 2017 02:36
-
-
Save ksunair/5d1b4062135ef62960528dbdc552a65a 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 (..) | |
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 = model.firstName ++ model.firstName | |
, 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 [] [] | |
, 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