Multi-value form element
4,764 sites
No security coverage
This module allows you to create form elements that can repeat multiple times, similar to how fields can have multiple values. It enables users to add, remove, and reorder sets of form fields, such as name and email inputs for contacts.
Provides a multi-value form element that wraps any number of form elements.
The wrapped elements will be repeated based on the cardinality specified on the wrapper.
It basically brings the delta cardinality concept of fields to form elements.
Each set of child elements ("delta") can be re-ordered with drag-and-drop.
$form['contacts'] = [
'#type' => 'multivalue',
'#title' => $this->t('Contacts'),
'#cardinality' => MultiValue::CARDINALITY_UNLIMITED,
'name' => [
'#type' => 'textfield',
'#title' => $this->t('Name'),
],
'mail' => [
'#type' => 'email',
'#title' => $this->t('E-mail'),
],
];