how to get multiple value from autocomplete?

I have

$form['group']['one'] = array(         '#type' => 'entity_autocomplete',         '#title' => t('Tags'),         '#target_type' => 'user', ); 

and i put the value like this:

user00 (0), user01 (1), user02 (2), user0x (3)

but then when i submit the form, i receive:

one = 3

it only pick the last id.


how i can get the whole input from user?


when there is input that is not-found (e.g. randomtext, user00), how autocomplete will handle it?



The comma is used to separate multiple references, but looking at the code in Name::valueForm() I would say the form element needs to use a property more.

  $form['value'] = array(
    '#type' => 'entity_autocomplete',
    '#title' => $this->t('Usernames'),
    '#description' => $this->t('Enter a comma separated list of user names.'),
    '#target_type' => 'user',
    '#tags' => TRUE,
    '#default_value' => $default_value,
    '#process_default_value' => $this->isExposed(),

Settings #tags to TRUE makes the the form element accept multiple values.

As for getting the submitted values, Name::valueValidate() uses the following code.

  $uids = [];
  if ($values = $form_state->getValue(array('options', 'value'))) {
    foreach ($values as $value) {
      $uids[] = $value['target_id'];
  $form_state->setValue(array('options', 'value'), $uids);

It uses array('options', 'value') because the form element is in a nested array (with #tree set to TRUE).

Category: 8 Time: 2016-07-29 Views: 0
Tags: autocomplete

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.244 (s). 12 q(s)