-
-
Save danneu/958d6f39a6e33721dda98b5dddc3a2be to your computer and use it in GitHub Desktop.
Elm defaultValue vs value -- Paste into http://elm-lang.org/try
This file contains hidden or 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 (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (onInput, onClick) | |
main = | |
Html.beginnerProgram { model = Model "" "", view = view, update = update } | |
type alias Model = | |
{ defaultValueEg : String | |
, valueEg : String | |
} | |
view model = | |
div [] | |
[ h1 [] [ text "Using defaultValue" ] | |
, textarea [ onInput Text1Input, defaultValue model.defaultValueEg ] [] | |
, button [ onClick ResetText1 ] [ text "Reset" ] | |
, h1 [] [ text "Using value" ] | |
, textarea [ onInput Text2Input, value model.valueEg ] [] | |
, button [ onClick ResetText2 ] [ text "Reset" ] | |
, div [] [ text (toString model) ] | |
] | |
type Msg | |
= Text1Input String | |
| ResetText1 | |
| Text2Input String | |
| ResetText2 | |
update msg model = | |
case msg of | |
Text1Input str -> | |
{ model | defaultValueEg = str } | |
ResetText1 -> | |
{ model | defaultValueEg = "" } | |
Text2Input str -> | |
{ model | valueEg = str } | |
ResetText2 -> | |
{ model | valueEg = "" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment