I have an entity_autocomplete field in a form.
$element['content'] = array(
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#title' => t('Content'),
'#title_display' => 'hidden',
'#default_value' => $content_default,
'#selection_handler' => 'default',
'#selection_settings' => array(
'target_bundles' => $selected_bundles,
),
'#prefix' => '<div class="container-inline">'
);
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' => 'Drupal\MODULE\Plugin\Field\FieldWidget\WIDGET::METHOD',
'wrapper' => $id,
'method' => 'replace',
'progress' => array(
'type' => 'throbber',
'message' => "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.