Created
August 31, 2017 03:35
-
-
Save ksunair/e623ad41c806a173d2355dbe6d9519c6 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 [] [] | |
, 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