Skip to content

Instantly share code, notes, and snippets.

Created July 26, 2017 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5b8e73ad676ba2300bc50b665a9425a2 to your computer and use it in GitHub Desktop.
Save anonymous/5b8e73ad676ba2300bc50b665a9425a2 to your computer and use it in GitHub Desktop.
Form Event Bubbling
{
"version": "1.0.0",
"summary": "An efficient approach for handling changes with many controls on a page.",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 5.1.1",
"elm-lang/html": "2.0.0 <= v < 2.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
<html>
<head>
<style>
html {
background: #F7F7F7;
color: red;
}
</style>
</head>
<body>
<script>
var app = Elm.Main.fullscreen()
</script>
</body>
</html>
module Main exposing (..)
import Html exposing (Html, beginnerProgram, div, form, textarea)
import Html.Attributes exposing (name)
import Html.Events exposing (on)
import Json.Decode as Json
import Dict exposing (Dict)
type alias Model =
{ fields : Dict String String
}
type Msg
= Field String String
onInput tagger =
on "input" <|
Json.at [ "target" ] <|
Json.map2 tagger
(Json.field "name" Json.string)
(Json.field "value" Json.string)
model =
Model Dict.empty
update msg model =
case msg of
Field key value ->
{ model | fields = Dict.insert key value model.fields }
view model =
div []
[ form [ onInput Field ]
[ textarea [ name "a01b" ] []
, textarea [ name "b1c0" ] []
]
]
main =
beginnerProgram { model = model, update = update, view = view }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment