Nested containers: Group several inputs in one column.

A form element for lists of values, with sorting, AJAX add and remove, and limits.

Element Multiple is a developer module. It provides the form element type element_multiple for custom forms. The element renders a fieldset with a table of rows, drag-and-drop sorting and AJAX add and remove operations, and it can limit the number of rows. The module has no admin interface.

Features

  • Single or composite rows, with several columns, headers and keyed rows.
  • Drag-and-drop sorting, with a weight fallback that works from the keyboard and on small screens.
  • AJAX add and remove, and an "Add more" button with a number of rows.
  • Cardinality, minimum rows and a hard cap on rows.
  • Required children, #states between the fields of a row, machine_name and date children.
  • Server-only children: value and #access FALSE children never travel through the browser.
  • #is_empty and #row_alter callbacks to decide which rows count and to change a single row.
  • Icons that follow the text color, so the element works on light and dark admin themes.

Usage

A list of text values:

$form['tags'] = [
  '#type' => 'element_multiple',
  '#title' => $this->t('Tags'),
  '#default_value' => ['Alpha', 'Beta', 'Gamma'],
];

The submitted value is the list of rows, in the order of the table. Empty rows are dropped.

Documentation

The documentation site explains every option of the element with an example and a screenshot, and the property reference lists every property with its type and default.

Looking for Drupal support?

Premium support from the project maintainers
Get in touch with us
Supporting organizations: 

Project information

Releases