Skip to content

Instantly share code, notes, and snippets.

@ksunair
Created August 31, 2017 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksunair/59cd0ac4f7bf7ac24971da200bb554a3 to your computer and use it in GitHub Desktop.
Save ksunair/59cd0ac4f7bf7ac24971da200bb554a3 to your computer and use it in GitHub Desktop.
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