Problem/Motivation

I would like to use this module in custom form. I am not sure how to use it.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

peijun created an issue. See original summary.

mark_fullmer’s picture

This module is not intended to be used for building forms with horizontal tabs. It is for presenting horizontal tabbed content to end-users.

For creating forms with horizontal tabs, you could explore using https://www.drupal.org/project/field_group . With this module, you can either use the Manage Fields UI to set fields to be displayed with horizontal tabs, or you can use form_alter() logic, along with the module-provided horizontal_tabs field element, as shown below:

    $form['tabs'] = [
      '#type' => 'horizontal_tabs',
      '#tree' => TRUE,
      '#weight' => 100,
    ];
    $form['tabs']['display_configuration'] = [
      '#type' => 'details',
      '#title' => $this->t('Display configuration'),
      '#description' => $this->t('<em>Control the behavior of this content in.</em>'),
    ];
    $form['tabs']['basic_information'] = [
      '#type' => 'details',
      '#title' => $this->t('Basic Information'),
      '#description' => $this->t('<em>Content in this section displays prominently atop pages.</em>'),
    ];

Alternatively, you could use this module (Bootstrap Horizontal Tabs) as a model for rolling your own horizontally-tabbed form using the underlying Bootstrap library: https://getbootstrap.com/docs/5.0/components/navs-tabs/

gravelpot’s picture

Status: Active » Closed (works as designed)