Discussion:
[elm-discuss] Newbie program not working correctly
Casper Bollen
2017-06-23 09:08:35 UTC
Permalink
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?
--
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.
Peter Damoc
2017-06-23 11:37:03 UTC
Permalink
Hi Casper,

Just force an empty value when the age is 0
Like this:
https://ellie-app.com/3yrgPqxp52ha1/0
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
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
For more options, visit https://groups.google.com/d/optout.
--
There is NO FATE, we are the creators.
blog: http://damoc.ro/
--
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.
Casper Bollen
2017-06-23 11:49:39 UTC
Permalink
Of course, thanks!
Post by Peter Damoc
Hi Casper,
Just force an empty value when the age is 0
https://ellie-app.com/3yrgPqxp52ha1/0
Post by Casper Bollen
https://ellie-app.com/3ynWqjPcP87a1/0.
In this program I calculate the correct input field according to the
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
For more options, visit https://groups.google.com/d/optout.
--
There is NO FATE, we are the creators.
blog: http://damoc.ro/
--
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.
Loading...