I would like to change the active tab on page load based a field value from the content type the quicktab block is on. For example say the content type is "process" and it has a list text field with options "stage 1, stage2, stage3 and stage4". I have also created corresponding quick-tabs with each stage in them like this - [stage 1][stage 2][stage 3][stage 4]. If that field is set to stage 2, then I would like "stage 2" to be the default active tab on page load.

Could you give an idea at what the best approach to this problem may be?

Comments

IWasBornToWin’s picture

Priority: Normal » Major

same here, any suggestions>

radimklaska’s picture

Status: Active » Fixed

For regular quicktabs instances you can use hook_quicktabs_alter, see http://drupalcode.org/project/quicktabs.git/blob/refs/heads/7.x-3.x:/qui...

Example:

/**
 * Alter the Quicktabs instance before it gets rendered.
 *
 * @param &$quicktabs
 *   A loaded Quicktabs object, either from the database or from code.
 */
function MYMODULE_quicktabs_alter(&$quicktabs) {
  // Choose quicktabs instance
  if ($quicktabs->machine_name == 'NAME_OF_YOUR_QT_INSTANCE') {
    // Choose second tab as default (first = 0)
    $default_delta = 1;
    // Make sure tab exists
    if ($default_delta >= 0 && count($quicktabs->tabs) - 1 <= $default_delta) {
      $quicktabs->default_tab = $default_delta;
    }
  }

The only thing left is to replace $default_delta = 1; with your logic. $quicktabs->tabs should contain some more info you can grab on.

radimklaska’s picture

Category: support » bug
Status: Fixed » Active

Oh, the thing is, that hook_quicktabs_alter does not fire when quicktabs are used as views style plugin becouse drupal_alter('quicktabs', $info); is inside if ($info = quicktabs_load($name)) { which is NULL for views...

Marking it as bug because ability to alter quicktabs is broken in this case.

webxtor’s picture

That's exactly the case I am trying to find a solution for! To alter the quicktabs used as a views plugin.

gratefulsk’s picture

Issue summary: View changes

I've been wanting to do this for the last couple of years, but have been unable to. Luckily I've had decent workaround using jQuery cookie. What I did was included the jQuery cookie library (https://github.com/carhartl/jquery-cookie) and added the following script to all pages.

// enable quicktabs memory
(function ($) {
  Drupal.behaviors.quicktabsHistory = {
    attach: function(context, settings) {

      $('.quicktabs-wrapper', context).each(function() {
        var id = $(this).attr('id');
        var tab = $.cookie(id);

        if (tab != '') {
          $(this).find('ul.quicktabs-tabs a#' + tab).click();
        }
        $(this).find('ul.quicktabs-tabs a').click(function() {
          $.removeCookie(id, {path: '/'});
          $.cookie(id, $(this).attr('id'), {path: '/'});
        });
      });
    }
  };
})(jQuery); 
Todd Young’s picture

Some similar notions & tricks recorded here, in case they inspire you: http://allabouttodd.com/tags/quicktabs

smustgrave’s picture

Status: Active » Closed (outdated)

With D7 EOL approaching in a month I'm starting to triage the D7 side of quicktabs queue.

If still an issue or needed for 4.0.x (latest branch) feel free to reopen