Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Created November 14, 2019 21:45
Show Gist options
  • Select an option

  • Save chiroptical/dbf53f1deaaf1af1804b0289e5817760 to your computer and use it in GitHub Desktop.

Select an option

Save chiroptical/dbf53f1deaaf1af1804b0289e5817760 to your computer and use it in GitHub Desktop.
module Main exposing (..)
-- Input a user name and password. Make sure the password matches.
--
-- Read how it works:
-- https://guide.elm-lang.org/architecture/forms.html
--
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Model =
{ ingredients : List String
}
init : Model
init =
Model [""]
-- UPDATE
type Msg
= Name (List String)
| Add
update : Msg -> Model -> Model
update msg model =
case msg of
Name xs ->
{ model | ingredients = xs }
Add ->
{ model | ingredients = List.append model.ingredients [""] }
-- VIEW
view : Model -> Html Msg
view model =
div []
( List.append
( List.map (\x -> viewInput "text" "Ingredient" x) model.ingredients )
( List.singleton ( button [ onClick Add ] [ text "+" ] ))
)
viewInput : String -> String -> String -> Html msg
viewInput t p v =
input [ type_ t, placeholder p, value v ] []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment