[SOLVED] Strange radiobutton behaviour in 0.19

Hi all.
I made a litle app in elm 0.18, and then I ported it to 0.19. Quite easy, what to say!

But, in a fieldset where I had two radiobuttons, I realised an extrange behaviour:

One of the options was set by default, that’s ok, but when I selected the other option, it sent the convenient Msg, but the option remained unselected!

It is not the case in 0.18, where it behaves like expected, leaving the last clicked radiobutton as selected, so, I don’t know if I missed some point in the porting (or coding), or there is a bug in 0.19.

I took the snippet in question into ellie-app (small, concise). If anyone can have a look, I would appreciate.

https://ellie-app.com/4MddP64JqVza1

Thank-you!

Hi @jbatlle,

In your view function:


view: Model -> Html Msg
view model =
    div []
        [ fieldset []
            [ text "Set option: "
            , radiobutton "One" (SetOption ValueOne) True
            , radiobutton "Two" (SetOption ValueTwo) False
            ]
        , selectionMessage model
        ]

You set the first radio button to be not selected and the second to be selected. You are not setting the default value here, you are setting the value.

To get the behaviour you want, you need to store which radio button is selected in your model and set it dynamically.

Hope that helps!

Grreat! Thanks!

I see the point. That ‘true’ at the end is setting that option forever!
I’ll fix it!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.