Question

I am facing a problem with a CheckBoxMultipleChoice in Wicket.

Let's assume the optiones are:

[] White
[] Black 
[] Blue 
[] Yellow 
[] Red 
[] None of the above

What I have to do, is to notice when "None of the above" is clicked and then uncheck the rest of the choices. And if "None of the above" is selected and the user clicks on any other option, i.e. "Red", then "None of the above" must be unchecked.

I can detect the values when the checkbox group changes, but I can't say which one was the exact option that was clicked, so I can see, for example, that the user chose "Red" and "None of the above" but I can not say if he just clicked in "Red" or in "None of the above", so I don't know what do if I have to uncheck "Red" or "None of the above"...

Was it helpful?

Solution

You can't really determine which checkbox was clicked first without catching the event in Javascript. What you're trying do is basically the same as a "select all" checkbox, except inverted in the case where you select it (everything else gets deselected) and I'm assuming just doing nothing in case it gets deselected.

Have a look at how Wicket's CheckboxMultipleChoiceSelector does it (particularly what AbstractCheckSelector and CheckboxSelector.js do). The code there adds click handlers to all the checkboxes plus the "select all" checkbox. The ones on the regular checkboxes update the "select all" and vice versa. You basically need the same, except you invert the effects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top