Is it possible to use this module in custom forms?

Created on 29 March 2022, about 3 years ago
Updated 1 June 2024, 10 months ago

I love this module to create clean user interfaces for nodes, users, terms, ...

BUT, can I also use it in custom forms, with drupal form API? I have tried setting the #type of a fieldset to "tabs", but it is not working

    $form['tabs'] = [
      '#type' => 'tabs',
      '#title' => $this->t('Tabs'),
      '#format_type' => 'tabs',
      '#format_settings' => [
        'direction' => 'vertical',
      ],
    ];
    $form['tab1'] = [
      '#type' => 'tab',
      '#title' => $this->t('Tab'),
      '#group' => 'tabs',
      '#format_type' => 'tab',
    ];

    $form['myelement'] = [
      '#type' => 'select',
      '#title' => $this->t('My element),
      '#options' => [
        '1' => '1',
        '2' => '2',
        '3' => '3',
      ],
      '#group' => 'tab1',
    ];
πŸ’¬ Support request
Status

Closed: works as designed

Version

3.0

Component

Miscellaneous

Created by

πŸ‡§πŸ‡ͺBelgium weseze

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    Yes, I've gotten it to work like this:

    
        $form['my_tabs'] = [
          '#type' => 'horizontal_tabs',
        ];
    
        $form['tab_content'] = [
          '#type' => 'details',
          '#title' => $this->t('Tab Content'),
          '#open' => TRUE,
          '#group' => 'my_tabs',
        ];
    
        $form['another_tab'] = [
          '#type' => 'details',
          '#title' => $this->t('Another Tab'),
          '#group' => 'my_tabs',
        ];
        
        $form['tab_content']['my_field'] = [
          '#type' => 'textfield',
          '#title' => $this->t('An awesome textfield'),
        ];
    
    
  • πŸ‡²πŸ‡ΌMalawi chancenyasulu

    #3 works for me

  • Status changed to Closed: works as designed 10 months ago
  • πŸ‡§πŸ‡ͺBelgium nils.destoop

    You can idd use the elements in custom forms. But you should use the correct types like shown in #3.

Production build 0.71.5 2024