Skip to content

Instantly share code, notes, and snippets.

@ksunair
Created August 31, 2017 02:36
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/5d1b4062135ef62960528dbdc552a65a to your computer and use it in GitHub Desktop.
Save ksunair/5d1b4062135ef62960528dbdc552a65a to your computer and use it in GitHub Desktop.
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