vaadin/flow-components

CheckboxGroup ItemEnabledProvider not working on value change.

KonstantinosNeiros opened this issue · 2 comments

Describe your motivation

In vaadin 8, by using CheckBoxGroup.setItemEnabledProvider(item -> {}; I was able to decide the status of a checkboxgroup item. In the debugging mode, I saw that each time I click an item, the above code is executed.

In vaadin 23, it seems that the code is executed just to set the initial status. On value change of the checkbox group items the code is not executed.

Describe the solution you'd like

The itemEnabledProvider should be executed each time the value of a checkbox group item changes.

Describe alternatives you've considered

No response

Additional context

No response

checkboxGroup.addValueChangeListener(e -> {
checkboxGroup.setItemEnabledProvider(x -> {
System.out.println(x);
return true;
});
});

this code resets the status provider each time a value changes. but of course it is not an appropriate approach.

While automatically "refreshing" the enabled items when items are checked/unchecked is clearly useful for one specific case: where the enabled-state of items is based on the state of other items, it would be unnecessary for all other use cases, so I don't think it should automatically refresh like that (even though it did so in V8).

However, I would expect refreshAll to re-run the enabledProvider on all items, so if you do:

checkboxGroup.addValueChangeListener(e-> {
  checkboxGroup.getDataProvider().refreshAll();
}

I would expect it to work the way you want.

Please leave a comment here if that solution doesn't work for you.