( Issue https://www.drupal.org/node/1402816 already pointed out the problem, but had been marked closed before.
Please see for screenshots: https://www.drupal.org/node/1402816#comment-11962577
I would have reopened the other issue, but it did not let me do that).

You can't currently easily set an active horrizontal tab.

There is a way to use a hidden field in the form, that is processed by JS:

$form['active_horizontal_tab'] = array(
    '#attributes' => array('class' => 'horizontal-tabs-active-tab'),
    '#type'       => 'hidden',
    '#value'      => 'some_id'
  );

As "jiv_e" pointed out correctly in the above mentioned issue, this is processed in the file horizontal-tabs.js, like so:

...
 var focusID = $(':hidden.horizontal-tabs-active-tab', this).val();
 ...

 ...
 if (this.id == focusID) {
     tab_focus = $(this);
}
...

The JS then tries to find the IDs of all fieldsets, and checks if those are equal to the the one listed here.

The problem is, there is no way in the system to input an ID, using the provided fieldset widgets The JS refers to something that cannot be set. As a result, the active tab can never be specified.

I would therefore request to have IDs be set for the individual htabs, using the interface.

There is a workaround I found; I was able to set an ID this way in the code, but many Drupal users would not be able to do that
$form['#groups']['my_htab']->format_settings['instance_settings']['id'] = 'some-id';
Maybe you can also do something similar using the hooks provided. However, I see that only as a workaround, where the real solution would be to simply input an ID for the htab.

Comments

hoporr created an issue. See original summary.

derekw’s picture

Ran across the same issue recently. Workaround: Set the tab to be a div temporarily, set the ID, then change it back to a tab. The ID will stick even though there's no field for it in the tab widget.

sime’s picture

Status: Active » Closed (works as designed)

Noting the workaround, but I wonder if this is still an issue - i saw the ability to have named linked in horizontal tabs was added, which means an ID would be added?