How to populate an Entity Reference field from a modal AjaxResponse?
Figured out it was the InvokeCommand i needed and to set "val" to the referenced entity title with id in ().

  $nid = $form_state-&gt;getValue('nid');
  $node = Node::load($nid);
  $value = $node-&gt;getTitle() . ' (' . $nid . ')';

  $response = new AjaxResponse();
  $response-&gt;addCommand(new CloseModalDialogCommand());
  $response-&gt;addCommand(new InvokeCommand('#edit-field-ref-to-bundle-a-0-target-id', 'val', [$value]));
  $form_state-&gt;setResponse($response);