I have an entity reference field on my content type using the autocomplete widget.

I'm adding an ajax callback to that field using this in a form alter:

$form['field_er']['widget'][0]['target_id']['#ajax'] = [
  'callback' => '::ajaxCallback',
  'event' => 'autocompleteselect',
  'wrapper' => 'nm-resend-selector',
  'progress' => [
    'type' => 'throbber',
    'message' => t('Updating.'),

The ajax call triggers when I select an entity, but in my form alter when I use $formState->getValue('field_er') the target_id is null, when it should be the id of the entity I selected.

How do I get at the selected entity?

Edit: I looked into FormState::input to see if I could get the value from there, but the value there is 'a' which is the text I entered to trigger the autocomplete.

1 Answer 1


Looks like I was just using the wrong event, switching the event to 'autocompleteclose' gets me the value I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.