2

I'm using jquery Tools tabs and would like to disable a particular tab (e.g. current tab), sometime after it has been initialized, e.g. on button click.

This is the code that I have now, which does work, but I'm wondering whether there are better solutions.

Imagine I have a "disable" button that runs this:

//disable all tabs except for current tab
$("ul.tabs").tabs("div.panes > div", function(ev,index){
    if (index != this.getIndex()){
        return false;
    }
})

and then an "enable tabs" button that does this:

$("ul.tabs").tabs("div.panes > div") //enables all tabs (by not disabling any)

The problem is, if I'm not mistaken, that I'm reinitializing the tabs each time, instead of modifying an the original existing instance. Is there a better solution?

fortuneRice
  • 4,214
  • 11
  • 43
  • 58
  • 2
    not sure if you'd be interested in a different plugin, but [jqueryui tabs](http://jqueryui.com/demos/tabs/#method-disable) has this functionality out of the box. – David Wick Jun 20 '11 at 02:22
  • @David thanks for the suggestion +1. I'll leave this question as a reference for anyone who might be interested in a jQuery Tools solution nonetheless. – fortuneRice Jun 20 '11 at 07:20

1 Answers1

1

According to the jQuery TOOLS Tabs Wizard Demo you can alter the onBeforeClick event and return false on the tab you want to disable.

Here's a shortened copy of the code from tabs wizard documentation

$("ul.tabs").tabs("div.panes > div", function(event, index) {
    /* now we are inside the onBeforeClick event */
    if (index == 1 OR index == MYDISABLEDTAB)  {
        // when false is returned, tab cannot be activated
        return false;
    }

    // everything ok
});
domi27
  • 6,903
  • 2
  • 21
  • 33