jQuery-EasyTabs icon indicating copy to clipboard operation
jQuery-EasyTabs copied to clipboard

Disabling tabs

Open cavidano opened this issue 11 years ago • 7 comments

Hi,

I would like you disable the actual tabs, but still leverage the core tab functionality. Such as Next, Previous, and active tab for example. I am building a form which needs validation so if nothing is selected (or incorrectly inputted) The user is restricted from advancing to the next tab. Here is the example:

http://unicef.milestone-creative.com/natcom-donor-toolkits/compare-countries.php

Thank you for your input.

Carl

cavidano avatar Sep 20 '13 15:09 cavidano

I think your best bet would be to just hide the tabs with display: none in your CSS. Then you can just use buttons to attach the public select method, and bind to the easytabs:before event hook and return false if you want to disallow advancing to the next tab.

JangoSteve avatar Sep 20 '13 16:09 JangoSteve

Steve,

Thank you for your speedy reply. I am not sure that's the approach I want to take. Visually I want the tabs there. Is there no way to simply disable the click state and rely on the public select method for the next previous buttons? These are great tabs by the way!

Thanks, Carl

cavidano avatar Sep 20 '13 21:09 cavidano

Oh, I thought you were saying you didn't want tabs. To disable their click events, just use plain jQuery:

$('.my-tabs').on('click', function(e) {
  return false;
});

JangoSteve avatar Sep 20 '13 21:09 JangoSteve

Thanks. I have tried everything to cancel these out, with no avail. Do you offer support (I will pay you) to set these up properly? This is a big project and has to be done correctly.

http://unicef.milestone-creative.com/natcom-donor-toolkits/compare-countries.php

Thanks again, Carl

cavidano avatar Sep 20 '13 21:09 cavidano

I could, but I honestly think we can do this right without official support ;-)

If the above doesn't work, how about this:

var tabs = $('#my-tabs-container');
tabs.easytabs();

// here's where the magic happens
tabs.on('easytabs:before', function(event) {
  var clicked = $(event.target);

  // test to see if the clicked element matches the selector for the tabs
  if (clicked.is('.my-tabs a')) {

    // if so, return false, since easytabs won't change tabs when
    // easytabs:before event returns false
    return false;
  }
});

JangoSteve avatar Sep 20 '13 21:09 JangoSteve

JangoSteve, your solution doesn't work in my case because I'm using Previous/Next buttons within the tab container div, and your code disables them too. The event target picked up by the easytabs:before handler is always the whole container, regardless of the element that was clicked within it that called easytab().

nicolasconnault avatar Aug 28 '14 03:08 nicolasconnault

My work-around was to add a transparent div over the tabs, with absolute positioning and a high z-index. A bit hacky, but works perfectly.

nicolasconnault avatar Aug 28 '14 03:08 nicolasconnault