Guest User

Untitled

a guest
Jul 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. module Main exposing (..)
  2.  
  3. import Html exposing (..)
  4. import Html.Attributes as Attrs exposing (..)
  5. import Html.Events exposing (..)
  6.  
  7.  
  8.  
  9.  
  10. type Msg
  11. = SetPrice String
  12.  
  13.  
  14. type alias Model =
  15. { price : Float }
  16.  
  17.  
  18. model : Model
  19. model =
  20. { price = 0 }
  21.  
  22.  
  23. update : Msg -> Model -> ( Model, Cmd Msg )
  24. update msg model =
  25. case msg of
  26. SetPrice price ->
  27. ( { model | price = price |> String.toFloat |> Result.withDefault 0 }
  28. , Cmd.none
  29. )
  30.  
  31.  
  32. view : Model -> Html Msg
  33. view model =
  34. div []
  35. [ Html.form []
  36. [ label [] [text "Price"]
  37. , input [placeholder "Price", value (toString model.price), onInput SetPrice ] []
  38. , br [] []
  39. , p [] [ text ("Price is: " ++ (toString model.price)) ]
  40. ]
  41. ]
  42.  
  43.  
  44. main : Program Never Model Msg
  45. main =
  46. Html.program
  47. { init = ( model, Cmd.none )
  48. , update = update
  49. , subscriptions = \_ -> Sub.none
  50. , view = view
  51. }
Add Comment
Please, Sign In to add comment