Question

I have a GWT Bootstrap ButtonGroup of radio type that I've created programatically in my GWT app. The creation looks more or less like:

ButtonGroup bg = new ButtonGroup();
bg.add(new Button("Button 1"));
bg.add(new Button("Button 2"));
bg.setToggle(ToggleType.RADIO);

This results in a 2-option selection box that is mutually exclusive. Upon page load neither button is selected, however once a user selects a button there's no way to "unselect" or clear the choice.

I'd like to programatically reset the ButtonGroup to have no selection made (it has to be programmatic due to constraints I'm operating under).

The ButtonGroup Javadoc however seems to imply there's no method for "resetting" the ButtonGroup.

Ideas?

Was it helpful?

Solution

So basically you want to "deactivate" a button if it was "activated". Try something like this for each button (not tested)

button.addClickHandler(new ClickHandler() {
 public void onClick(ClickEvent event) {
      if(button.getStyleName().equals("active"){
            button.removeStyleName("active");
      }
}});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top