views:

3317

answers:

2

I tried to disable tab navigation using

var $tabs = $("#tabs").tabs({
    select: function(event, ui) { return false; }
});

However, this also disables the flow links I'm using for navigation:

$('input.nexttab').click(function() {
    var tab_num = $tabs.tabs('option', 'selected');
    // error check this tab before proceeding
    if ( check_tab(tab_num) ) {
        $tabs.tabs('select', tab_num + 1 );
    }
});

Ideally, I'd want to disable tab navigation for tabs to right of current tab, and ensure my <<prev and next>> tab navigation buttons always work.

Any suggestions?

A: 

You should store a flag on the first closure, in the function you pass to $(document).ready, set it true when your next/prev buttons are clicked, and set back to false when the tab has been shown, by doing so, you will be only able to change tab by using the buttons.

Check this working sample and the following code snippet:

$(document).ready(function(){ 
  var allowTabChange = false; 
  var $myTabs = $("#tabs"); 

  $myTabs.tabs({ 
                    select: function(event, ui) { return allowTabChange; }, 
                    show: function(event, ui) { allowTabChange = false; }, 
               }); 

  $('#nextButton').click(function(){offsetTab(1);}); 
  $('#prevButton').click(function(){offsetTab(-1);}); 

  // Helper functions

  function offsetTab(offset){ 
    var tab_num = $myTabs.tabs('option', 'selected'); 
    var nextTab = tab_num + offset; 

    if ( check_tab(nextTab) ) { 
      allowTabChange = true; 
      $myTabs.tabs('select', nextTab); 
    } 
  }

  function check_tab(tab_num){        
    return tab_num >= 0 && tab_num < $myTabs.tabs('length'); 
  } 
});
CMS
Hmmmm, seems a little messy - I was hoping there's would be a one liner to easily add/remove the event handler from the tabs. I could live with all tabs being disabled as long as the prev/next links work (to simplify the logic). Use a selector on the .ui-tabs-nav class elements and delete the click event? Would that work?
+3  A: 

Have you tried setting the event option to something that isn't likely to be fired (if at all)?

For instance:

$('#tabs').tabs({ event: 'change' });

or

$('#tabs').tabs({ event: '' }); //probably better
Jason Berry
+1 setting it to onchange works fine, empty doesn't though. Odds are that the tab control won't fire an onchange anyway.
jfrobishow