4

Possible Duplicate:
How to enable or disable an anchor using jQuery?

I'm having a hard time disabling the anchor. I've read that there's an existing bug with Anchor.SetEnabled.

anchor().setEnabled(false) does not work due to browser constraints. However, is there another way to disable/enable the link?

Community
  • 1
  • 1
scriptgeeky
  • 185
  • 1
  • 2
  • 8

3 Answers3

5
// to disable the anchor
disabled = anchor.addClickHandler(new ClickHandler() {
   @Override
   public void onClick(ClickEvent event) {
      event.preventDefault();
   }
});

// to re-enable it.
disabled.removeHandler();
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • `clickListener` doesn't prevent `onHistroryChange()` event which is responsible for adding a history token. – Mohsen Aug 22 '12 at 13:39
  • The question is about `Anchor`, not `Hyperlink` or `InlineHyperlink`. Note how `addClickHandler` in `Hyperlink` is deprecated and suggests using an `Anchor` and calling `History.newItem` by yourself if you want to "process the click before the history token is set". – Thomas Broyer Aug 22 '12 at 13:49
0

You can for example change href, or make onClick events no-ops.

milan
  • 11,872
  • 3
  • 42
  • 49
0

I had a similar problem. the most suitable solution for me was to download the custom Anchor class given in the end of this issue and use it instead of the GWT Anchor. It work from the first try !

Momo
  • 2,471
  • 5
  • 31
  • 52