Skip to content

Min and empty items

The number of rows at first is the number of default values plus #empty_items. It is at least #min_items and at most #cardinality.

Set both to 0 and the table is replaced by a message. #no_items_message changes the message.

$form['notes'] = [
'#type' => 'element_multiple',
'#title' => $this->t('Notes'),
'#min_items' => 0,
'#empty_items' => 0,
];

The message is No items entered. Please add items below.. To change it, set #no_items_message.

$form['notes']['#no_items_message'] = $this->t('No notes yet. Use the button below.');

An empty list that shows the message No items entered and the Add more control.

#min_items keeps a number of rows on screen, even when there are no values. A row cannot be removed below it.

$form['notes'] = [
'#type' => 'element_multiple',
'#title' => $this->t('Notes'),
'#min_items' => 3,
];

An empty list that shows three blank rows with a plus button each and no minus buttons.