Clearable radio button group

Hi
I want to use radioButtonGroup instead of entityComboBox when I only 2-3 elements in the optionsList. entityComboBox offers an option isNullOptionVisible but I can’t find an equivalent in the radioButtonGroup.
When we use a radioButtonGroup is there a way to clear the value using UI ?
I wanted to be able to clear the value when user click on the same option again but it didn’t work because addValueChangeListener is only firing when data actually changes (so it.prevValue == it.value is never true)
In your opinion what would be the best alternative to achieve this ?

Jmix 1.5

If it’s allowed in your application to choose none of the other options, add a ‘none’ option and make this default.

Sure but it would require a lot of configuration as I need to add an extra option (‘none’) on every fields. if nothing is picked it would be logical to have null instead of ‘none’. Another argument is that it will complicate the UI a lot.
It feels weird that the initial state of the radio button cannot be retrieve once you pick one option. even on non-mandatory fields.

I find this question interesting, too.
Especially for non-required radios, there should be the option to click the already marked option and clear it thereby. I’ll post, if I find a solution. Kind of an extra event that clears the radio, when active option is clicked… (did this years ago in VB6, lots of libs of software controls have this problem…)

2 Likes

Vaadin recommendation is to put a ‘blank’ option. I don’t like to go against the recommendations but in my case it was way simpler to just add a clear button.

            cleanButton.addClickListener { value = null }

I still think that clicking the same option a second time to clear, would have been very intuitive and simple.