Casper Bollen
2017-06-23 09:08:35 UTC
I wrote a small program as a newbie project in
Elm: https://ellie-app.com/3ynWqjPcP87a1/0.
In this program I calculate the correct input field according to the value
in the model:
view : Model -> Html Msg
view model =
let
toInput attrs =
input attrs []
ageInput =
let
attrs =
if model.age == 0 then
[ name "age", type_ "number", placeholder "Leeftijd in jaren" ]
else
[ name "age", type_ "number", value (toString model.age) ]
_ =
Debug.log "Attrs" attrs
in
attrs
|> List.append [ onInput Update ]
|> toInput
in
div [ style [ ( "margin", "100px" ) ] ]
[ div [] [ text "Voer een leeftijd in" ]
, ageInput
, button [ onClick Calculate ] [ text "Bereken" ]
, div [] [ text ("Gewicht: " ++ toString (model.weight) ++ " kg") ]
]
However, if you count up and then down to zero, the input field is rendered
correctly showing the placeholder when age = 0. But when you count down to
negative values, the negative values are shown, although the model.age
value = 0.
Furthermore, the Debug.log "Attrs" is never shown in the debug view.
What am I doing wrong?
Elm: https://ellie-app.com/3ynWqjPcP87a1/0.
In this program I calculate the correct input field according to the value
in the model:
view : Model -> Html Msg
view model =
let
toInput attrs =
input attrs []
ageInput =
let
attrs =
if model.age == 0 then
[ name "age", type_ "number", placeholder "Leeftijd in jaren" ]
else
[ name "age", type_ "number", value (toString model.age) ]
_ =
Debug.log "Attrs" attrs
in
attrs
|> List.append [ onInput Update ]
|> toInput
in
div [ style [ ( "margin", "100px" ) ] ]
[ div [] [ text "Voer een leeftijd in" ]
, ageInput
, button [ onClick Calculate ] [ text "Bereken" ]
, div [] [ text ("Gewicht: " ++ toString (model.weight) ++ " kg") ]
]
However, if you count up and then down to zero, the input field is rendered
correctly showing the placeholder when age = 0. But when you count down to
negative values, the negative values are shown, although the model.age
value = 0.
Furthermore, the Debug.log "Attrs" is never shown in the debug view.
What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.