Add #ajax callback to an entity_autocomplete field I have an entity_autocomplete field in a form.

$element['content'] = array(
  '#type' =&gt; 'entity_autocomplete',
  '#target_type' =&gt; 'node',
  '#title' =&gt; t('Content'),
  '#title_display' =&gt; 'hidden',
  '#default_value' =&gt; $content_default,
  '#selection_handler' =&gt; 'default', 
  '#selection_settings' =&gt; array(
    'target_bundles' =&gt; $selected_bundles,
  ),
  '#prefix' =&gt; '&lt;div class="container-inline"&gt;'
);


I would like to add an #ajax callback to run after someone has selected a piece of content from the autocomplete drop-down, but I can't seem to find out how to attach it.

I have tried as follows which works for select boxes.

   $element['content']['#ajax'] = array(
      'callback' =&gt; 'Drupal\MODULE\Plugin\Field\FieldWidget\WIDGET::METHOD',
      'wrapper' =&gt; $id,
      'method' =&gt; 'replace',
      'progress' =&gt; array(
        'type' =&gt; 'throbber',
        'message' =&gt; "shuffling",
      ),
    );


However, it does not fire. Is it possible to do what i need?

It actually fires if you tab out of the field, but I need it to fire after a selection is made.
You can adjust the behavior with

'#ajax' =&gt; array(
  'event' =&gt; 'change',


This can be any javascript event. The default for a select is on 'change', for a normal field this is on 'blur'. But you can try any other event.

Reference: https://developer.mozilla.org/en-US/docs/Web/Events