Created
October 12, 2016 07:45
-
-
Save dadhi/ac1bdf5c3c83fbde97a489afee772e17 to your computer and use it in GitHub Desktop.
Small example if clearing input value in elm
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
import Html exposing (div, button, text, input, p) | |
import Html.App exposing (beginnerProgram) | |
import Html.Events exposing (onClick, onInput) | |
import Html.Attributes exposing (placeholder, value) | |
main = | |
beginnerProgram { model = model, view = view, update = update } | |
model = | |
{ personName = "" | |
, inputPersonName = "" | |
} | |
type Msg = Greet | InputPersonName String | |
view model = | |
div [] | |
[ input [ placeholder "person name", onInput InputPersonName, value model.inputPersonName ] [] | |
, button [ onClick Greet ] [ text "Greet" ] | |
, p [] [ text model.personName ] | |
] | |
update msg model = | |
case msg of | |
Greet -> | |
let | |
personName = model.inputPersonName | |
in | |
{ model | personName = personName, inputPersonName = "" } | |
InputPersonName name -> | |
{ model | inputPersonName = name } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment