Thanks Kasey,

I've run into that checkbox rendering issue in the past, when I've needed
some boxes to initialize as "checked". It does take a couple extra steps to
get it working.

Cheers!

On 27 June 2017 at 09:34, Kasey Speakman <[email protected]> wrote:

> In addition to the other answers, I also spotted one other "gotcha" in
> your example you may want to be aware of.
>
> Your checkbox does not render the "checked" attribute. Your browser tracks
> values for HTML form elements separately from Elm. Form values typically
> get overwritten with Elm values when the view is rendered. But in this
> case, nothing from Elm is setting whether the element should be checked.
> Try starting with `on = True` and the checkbox initially renders unchecked
> still.
>
> On Thursday, June 22, 2017 at 6:42:19 PM UTC-5, 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 a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/elm-discuss/YujY29aXFZk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to