Created
July 17, 2018 07:21
-
-
Save rajatk16/84b6bb93827dd9794a10ed715406bb07 to your computer and use it in GitHub Desktop.
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 (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (onClick, onInput, onSubmit) | |
type alias Model = | |
{ email : String | |
, message : String | |
, submitting : Bool | |
} | |
initialModel : Model | |
initialModel = | |
{ email = "" | |
, message = "" | |
, submitting = False | |
} | |
type Msg | |
= InputEmail String | |
| InputMessage String | |
| Submit | |
main : Program Never Model Msg | |
main = | |
program | |
{ init = (initialModel, Cmd.none) | |
, update = update | |
, subscriptions = \model -> Sub.none | |
, view = view | |
} | |
update : Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
InputEmail e -> | |
({model | email = e}, Cmd.none) | |
InputMessage m -> | |
({model | message = m}, Cmd.none) | |
Submit -> | |
({model | submitting = True}, Cmd.none) | |
view : Model -> Html Msg | |
view model = | |
Html.form | |
[ onSubmit Submit ] | |
[ header | |
, body | |
, footer | |
, div [] [model |> toString |> text] | |
] | |
header = div [] | |
[ h1 [] [ text "Feedback Form" ] ] | |
body = div [] | |
[ div [] | |
[ input | |
[ placeholder "E-Mail" | |
, type_ "email" | |
, onInput InputEmail | |
, required True | |
] [] ] | |
, div [] | |
[ textarea | |
[ placeholder "Message" | |
, rows 7 | |
, onInput InputMessage | |
, required True | |
] [] ] | |
] | |
footer = div [] | |
[ button | |
[ type_ "submit" ] | |
[ text "Submit" ] | |
, button | |
[ type_ "button" ] | |
[ text "Cancel" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment