Skip to content

Operations and add more

The element has two kinds of controls. The row buttons are in the operations column. The “Add more” control is below the table.

The default list with the plus and minus buttons in each row and the Add more control below the table.

The number input next to the button sets how many rows one click adds. It starts at #add_more_items, which is 1. Type 3 and click Add.

$form['rows'] = [
'#type' => 'element_multiple',
'#title' => $this->t('Rows'),
'#default_value' => ['One', 'Two', 'Three'],
];

To start the input at another number, set #add_more_items.

$form['rows']['#add_more_items'] = 3;

The list after the number 3 was typed and Add was clicked. Three empty rows follow the four rows of the first picture.

#operations => FALSE removes the column. The rows can only be reordered and edited. “Add more” stays.

$form['rows']['#operations'] = FALSE;

A list without the operations column.

#add_more => FALSE removes the control below the table. The row buttons stay.

$form['rows']['#add_more'] = FALSE;

A list with row buttons and no Add more control.

#add_more_input => FALSE keeps the button and removes the number. A click adds #add_more_items rows.

$form['rows']['#add_more_input'] = FALSE;

A list whose Add button has no number input.

#add => FALSE removes the per-row plus. #remove => FALSE removes the per-row minus.

$form['rows']['#add'] = FALSE;
$form['rows']['#remove'] = FALSE;