1

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?

Serdalis
  • 10,296
  • 2
  • 38
  • 58
Adam Parkin
  • 17,891
  • 17
  • 66
  • 87

1 Answers1

1

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");
      }
}});
Momo
  • 2,471
  • 5
  • 31
  • 52
  • Had to change the ```equals()``` to ```contains()``` as the button may contain other styles, but otherwise this is spot-on. Thanks! – Adam Parkin Feb 11 '14 at 22:27