Problem/Motivation

When using the render element (select_tagify) in a custom form, and specifying '#multiple' => TRUE, the user cannot select multiple values.

Steps to reproduce

Create a custom form with the following build() :

  public function buildForm(array $form, FormStateInterface $form_state): array {
    $values = $form_state->getValue('select') ?? [];
    $form['select'] = [
        '#type' => 'select_tagify',
        '#multiple' => TRUE,
        '#title' => 'Items',
        '#options' => [
            1 => 'A',
            2 => 'B',
            3 => 'C',
        ],
        '#default_value' => $values,
        '#attributes' => [
            'class' => ['foo'],
        ],
        '#identifier' => 'foo',
    ];
    $form['actions'] = [
        'btn-submit' => [
            '#type' => 'submit',
            '#value' => 'Submit',
        ],
    ];
    return $form;
  }

Then try to select multiple items.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

manuel.loth created an issue.

joelwinzer’s picture

There's a quick workaround. You need to set #mode to an empty string, and then it will work:
$form['form_element']['#type'] = 'select_tagify';
$form['form_element']['#mode'] = '';