First of all, great module - thanks for maintaining it!

I have two horizontal tabs named Saturday and Sunday used for adding/editing a node form. In the content type definition, Saturday defaults to open and Sunday defaults to closed. I would like to dynamically close Saturday and open Sunday.

From http://drupal.org/node/1370914, I thought I could use hook_field_group_pre_render_alter like so:

function lcog_bcc_field_group_pre_render_alter(&$element, $group, &$form) {
if ($group->format_type == 'htab') { //only change HTAB item 
	if ($element['#id']=='node_commute_form_group_saturday') {
			$group->format_settings['formatter']='closed';
		}
	if ($element['#id']=='node_commute_form_group_sunday') {
			$group->format_settings['formatter']='open';
		}
	}
}

but Saturday continued to show up as the open tab.

After dumping $element, $group and $form and looking for all other places where the tab states might be set, I added the following to the Saturday part of the code above:

$element['#collapsed'] = TRUE;
$group->collapsed = TRUE;
$group->classes .= 'collapsed ';
$form['group_commute_days']['group_saturday']['#attributes']['class'][4]='collapsed';

and this to Sunday:

$element['#collapsed'] = FALSE;
$group->collapsed = FALSE;
$group->classes=str_replace('collapsed ', '', $group->classes);
unset($form['group_commute_days']['group_sunday']['#attributes']['class'][3]);

but it did not help - Saturday is still showing as the default tab on the form.

Of course, I've cleared my cache every time. . .

I'm sure I'm just missing something obvious. Any ideas? Thanks so much. . .

Jeff

Comments

prinds’s picture

oops - sorry, posted in the wrong place..

haggins’s picture

I am setting #default_tab to the corresonding fieldsets ID in a custom $form array (i.e. '#default_tab' => 'edit-section-pricecategories-wrapper-content-types-2'). However, this setting seems to be ignored.

Did anyone get this working?

sylwester’s picture

the only way that I managed to get that working is by adding

<?php
     //add inline javascript
     drupal_add_js('
           window.location = "#'.$open_tab.'";
     ', 'inline');
?>

in hook_form_alter, where $opentab is ID of the horizontal tab set in structure -> content type -> manage fields.
Not pretty but it works.

fabioneves’s picture

Anyone managed to do this? I also want to set a tab dynamically.

rimu’s picture

Similar to #3, I got this working by setting an ID for the tab and then just had # in the URL of the page. e.g. node/20998/edit#group-signoff.

At first it wasn't working but clearing the cache seemed to be the final piece of the puzzle.

NB the ID I set had an underscore in it, but I needed to link to a version of the ID with a dash instead. OK, Whatever :)

e.bogatyrev’s picture

Hi there,

I faced with the same trouble but with vertical tabs. I think the solution should be work for horizontal tab as well, but didn't check.
To make the some tab is active by default we should implement the hook hook_field_group_build_pre_render_alter() and set the #value (should be an identifier of needed fieldset) for *__active_tab. Here an example

/**
 * Implements hook_field_group_build_pre_render_alter().
 */
function MYMODULE_field_group_build_pre_render_alter(&$element) {
  $element['additional_settings']['additional_settings__active_tab']['#value'] = 'identifier-of-fieldset';
}
tjerah’s picture

	$form['your_htabs'] = array(
		'#type' => 'horizontal_tabs',
		'#attached' => array('library' => array(array('field_group', 'horizontal-tabs'))),
		'#default_tab' => 'your-fieldset-identifier',
	);