Paul Freeman
2017-06-22 23:15:54 UTC
This is the first time I've posted to the community. I chose this group
over Slack or Reddit, so please nudge me if this problem would be better
suited in one of the other communities.
Basically, I'm noticing an inconsistency in the text value displayed in one
of my text boxes. It is based on the type in the text box that follows it.
I've got it down to the simplest example I could find, which demonstrates
the error on http://elm-lang.org/try
Here is the code:
import Html exposing (Html, p, div, text, input, beginnerProgram)
import Html.Attributes exposing (type_, value)
import Html.Events exposing (onClick)
main =
beginnerProgram { model = { on = False }, view = view, update = update }
type alias Model =
{ on : Bool }
type Msg
= Toggle
update msg model =
{ model | on = not model.on }
view : Model -> Html Msg
view model =
div [] <| p [] [ text "On: ", input [ type_ "checkbox", onClick Toggle
] []]
:: (if model.on then
[ p [] [ text "Foo: ", input [ value "foo" ] [] ] ]
else
[]
)
++ [ p [] [ text "Bar: ", input [ value "10.0"{-, type_ "number"-}
] [] ] ]
If the code is executed as shown, you will see a checkbox. When the box is
checked, a new input box appears and has the default value "foo" inside
it. But, if you include the commented code (in red), then the default value
"foo" is not shown when the box is checked. This is very odd since the
commented code is for a completely different text box.
I'm happy to use a workaround, if anyone knows one, but so far I haven't
come across anything. Any thoughts are welcome.
Thanks!
over Slack or Reddit, so please nudge me if this problem would be better
suited in one of the other communities.
Basically, I'm noticing an inconsistency in the text value displayed in one
of my text boxes. It is based on the type in the text box that follows it.
I've got it down to the simplest example I could find, which demonstrates
the error on http://elm-lang.org/try
Here is the code:
import Html exposing (Html, p, div, text, input, beginnerProgram)
import Html.Attributes exposing (type_, value)
import Html.Events exposing (onClick)
main =
beginnerProgram { model = { on = False }, view = view, update = update }
type alias Model =
{ on : Bool }
type Msg
= Toggle
update msg model =
{ model | on = not model.on }
view : Model -> Html Msg
view model =
div [] <| p [] [ text "On: ", input [ type_ "checkbox", onClick Toggle
] []]
:: (if model.on then
[ p [] [ text "Foo: ", input [ value "foo" ] [] ] ]
else
[]
)
++ [ p [] [ text "Bar: ", input [ value "10.0"{-, type_ "number"-}
] [] ] ]
If the code is executed as shown, you will see a checkbox. When the box is
checked, a new input box appears and has the default value "foo" inside
it. But, if you include the commented code (in red), then the default value
"foo" is not shown when the box is checked. This is very odd since the
commented code is for a completely different text box.
I'm happy to use a workaround, if anyone knows one, but so far I haven't
come across anything. Any thoughts are welcome.
Thanks!
--
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.