Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created October 12, 2016 07:45
Show Gist options
  • Save dadhi/ac1bdf5c3c83fbde97a489afee772e17 to your computer and use it in GitHub Desktop.
Save dadhi/ac1bdf5c3c83fbde97a489afee772e17 to your computer and use it in GitHub Desktop.
Small example if clearing input value in elm
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