If you replace the else branch with [ p [] [] ]
this problem does not seem to happen. I guess, the reason could be the following: In your version, if model.on is True, we get in total [ p [] [ text "On: ", input [ type_ "checkbox", onClick Toggle ] [] ] , p [] [ text "Foo: ", input [ value "foo" ] [] ] , p [] [ text "Bar: ", input [ value "10.0", type_ "number" ] [] ] ] and if it is False, we get [ p [] [ text "On: ", input [ type_ "checkbox", onClick Toggle ] [] ] , p [] [ text "Bar: ", input [ value "10.0", type_ "number" ] [] ] ] After inspecting the generated Html (Chrome), it seems that when I switch from False to True, the input field changes from <input type="number"> to <input type> Is this actually the expected behaviour? On Friday, 23 June 2017 01:42:19 UTC+2, Paul Freeman wrote: > > 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! > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
