Ajax form an multi-select I have a form which provides select2 when the select1 is changed. However I would like select2 to be a multi-select. I can't seem to get this to work. It populates a single select input just fine, but not the multi-select. Any tips would be appreciated.

public function buildForm(array $form, FormStateInterface $form_state, $options = NULL) {
  $form['expeditions'] = [
    '#type' =&gt; 'select',
    '#title' =&gt; $this-&gt;t('Choose Project'),
    '#empty_option' =&gt; $this-&gt;t('Select a project'),
    '#default_value' =&gt; '',
    '#options' =&gt; $options,
    '#ajax' =&gt; [
      'callback' =&gt; '::getDeployments',
      'wrapper' =&gt; 'deployment-wrapper',
    ],
  ];

  // Disable caching on this form.
  $form_state-&gt;setCached(FALSE);

  $form['deployment_wrapper'] = [
    '#type' =&gt; 'container',
    '#attributes' =&gt; ['id' =&gt; 'deployment-wrapper'],
  ];

  return parent::buildForm($form, $form_state);
}

public function getDeployments(array &amp;$form, FormStateInterface $form_state) {
  $expedition_id = $form_state-&gt;getValue('expeditions');
  if ($expedition_id != "") {
    $arms_config = \Drupal::config('arms.settings');
    $rest_root = $arms_config-&gt;get("arms_rest_uri");

    $client = \Drupal::service('http_client');
    try {
      $result = $client-&gt;get(
        $rest_root . 'arms/projects/' . $expedition_id,
        ['Accept' =&gt; 'application/json']
      );
      $expedition = json_decode($result-&gt;getBody());
    }
    catch (RequestException $e) {
      watchdog_exception('arms', $e);
      drupal_set_message('Error fetching project.', 'error');
    }
  }

  $options = [];

  foreach ($expedition-&gt;{'deployments'} as $deployment_id) {
    array_push($options, $deployment_id);
  }

  $form['deployment_wrapper']['deployments'] = [
    '#type' =&gt; 'select',
    '#title' =&gt; $this-&gt;t('Choose Deployment(s)'),
    '#options' =&gt; $options,
    '#multiple' =&gt; TRUE,
  ];

  return $form['deployment_wrapper'];
}
It is not possible to create a select element in an ajax callback, because the form builder needs to know about it.

Move all code from ajax callback to buildFrom(). Make this code conditional on form_state. 

Your callback contains only:

return $form['deployment_wrapper'];