Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (..)
- import Html exposing (..)
- import Html.Attributes as Attrs exposing (..)
- import Html.Events exposing (..)
- type Msg
- = SetPrice String
- type alias Model =
- { price : Float }
- model : Model
- model =
- { price = 0 }
- update : Msg -> Model -> ( Model, Cmd Msg )
- update msg model =
- case msg of
- SetPrice price ->
- ( { model | price = price |> String.toFloat |> Result.withDefault 0 }
- , Cmd.none
- )
- view : Model -> Html Msg
- view model =
- div []
- [ Html.form []
- [ label [] [text "Price"]
- , input [placeholder "Price", value (toString model.price), onInput SetPrice ] []
- , br [] []
- , p [] [ text ("Price is: " ++ (toString model.price)) ]
- ]
- ]
- main : Program Never Model Msg
- main =
- Html.program
- { init = ( model, Cmd.none )
- , update = update
- , subscriptions = \_ -> Sub.none
- , view = view
- }
Add Comment
Please, Sign In to add comment