tags:

views:

49

answers:

2

I would like to allow my users to re-enable a disabled checkbox on click. I tried to attach an onClickHandler to my checkbox but since it's disabled, it doesn't see to catch that event:

checkbox.onClickHandler(new ClickHandler() {
  public void onClick(ClickEvent clickEvent) {
    // do something
  }
});

Did I miss something? Or would I need to write my own checkbox that extends from CheckBox to do that?

A: 

You could try putting the CheckBox inside a FocusPanel, or similar. That way when the checkbox is disabled the click event will fall through to the FocusPanel, which can enable the checkbox for you. You might like to put event.stopPropagation() in the checkbox click handler to stop the focus panel click handler from being called when the checkbox is enabled.

I haven't tested this but I'm confident it will work. Be careful though. I'd recommend providing another means besides for enabling the checkbox, since a good number of your users won't understand that clicking on a disabled checkbox is going to have an effect.

hambend
A: 

Not an answer per se, but I ran into a similar problem trying to add a tooltip to a disabled button to tell the user why it was disabled but tooltips don't show for disabled items. I had to put the button inside a container and put the tooltip on the container.

VogonPoet