I am trying to base the visibility of a few form fields on the state of a checkbox, so I need to know when the checkbox has been clicked to be able to update my form.
First I made my Form implement Button.ClickListener and implemented the method buttonClick. This is similar to the
checkbox example in the Vaadin Sampler. The example in the sampler does not work, nothing happens when I activate the checkboxes.
@Override
public void buttonClick(ClickEvent event) {
Button source = event.getButton();
if (source == checkbox1) {
showOptions((Boolean)checkbox1.getValue());
}
}
Then I read in the Book of Vaadin that CheckBoxes should also work with ValueChangeListeners, so I implemented the example from the book:
I had checked what kind of settings the checkbox offers, but I must have missed the immediate part. At least I’m not alone with that kind of mistake, since someone did the same thing in the
sampler
Hi,
I have more or less the same issue as Alex.
I have a checkbox for which I have added a ValueChangeListener.
As proposed Heuri, I have set to immediate my checkbox (but with or without, I have the same behaviour).
When I check it (checkbox value is true), it’s working fine, I catch the event.
When I uncheck it (checkbox value is false) it’s not working, nothing append, I don’t catch the event !!!
So it’s just working when I click the checkbox (value true) but not when I click again to uncheck it (value false).
The action of unchecking a checkbox should also raise a ValueChangeEvent, no ?