it is working disable optiongroup.setItemEnabledProvider(item → !item.equals(“N”) ); But i want to re enable it how it possible any idea?
when do you want to re-enable the item?
in combobox value select i want to enable the item
Replacing the radio button group with a new instance based on the combo box could be the easiest. Otherwise the removal and addition of the listener could also work, even tho that feels more clunky
any example code?
I don’t have any example code by hand
I would not replace the entire RBG component instance, but the values in it. However, you could also have a fixed set of items and update their enabled states.
That of course means that the logic in your ItemEnabledProvider needs to be somehow based on the selection in the ComboBox, or that you have a ValueChangeListener on the ComboBox that affects something else that the ItemEnabledProvider uses.
And I think you’ll need to do getListDataView().refreshAll();
on the RBG for the enabled states to update (e.g. in the ValueChangeListener of the ComboBox)
here’s an example of a RBG with two Persons: Rolf and Rodolfo, and a Checkbox that determines whether only Rolf should be enabled:
Checkbox cbOnlyEnableRolf = new Checkbox("Only enable Rolf");
add(cbOnlyEnableRolf);
RadioButtonGroup<Person> rbg = new RadioButtonGroup<>("Peeps");
rbg.setItems(peeps);
rbg.setItemLabelGenerator(item->item.getFirstName());
rbg.setItemEnabledProvider(item->{
if (cbOnlyEnableRolf.getValue().booleanValue()) {
return item.getFirstName().equals("Rolf");
} else {
return true;
}
});
add(rbg);
cbOnlyEnableRolf.addValueChangeListener(e->{
rbg.getListDataView().refreshAll();
});
i am try your code sir it is working to disable radio value but it is not re enable it rbg.getDataProvider().refreshAll();(i have not available rbg.getListDataView() this method…
what Vaadin version do you have?
ah says 14 in the title, sorry
yes sir 14
then I think it’s rbg.getDataProvider().refreshAll()
it is not working sir?
how is it not working? not compiling? doesn’t re-enable the radio button?
actually, how about you paste your code here, that would probably help a lot
i will add my sample code
sample.txt (1.34 KB)
thanks.
So, what you want to do is to have ALL the rules of enabling/disabling in the ItemEnabledProvider, and the only thing you should do in the combo’s valuchangelistener is to call refreshAll
on the radiogroup.
The way I would structure it is to have an if
block for each radio-item that needs its own logic, and within that if
block define the rules, based on the combo’s value, in that block. For example:
optiongroup.setItemEnabledProvider(item->{
String format = comboLabelFormat.getValue();
if (item.equals("Primary Household Guardian")) {
if (!format.equalsIgnoreCase("To the Parents / Guardian of")) {
return false;
} else {
return true;
}
}
});```
btw, I highly recommend encoding those various string options (both in the radio group and in the combo) as enums so that you don’t have to juggle all those string literals everywhere.