No Ajax gets initialised from inside the modal I've got a bunch of forms that are opening inside a modal so that the user is not redirected off the page. I've then got a few Ajax calls on form items inside the form. They all work when using the form in a page instead of a modal, however when in a modal it just gets an Ajax error.

The simplest Ajax functionality is the following:

function hook_form_alter(&amp;$form, $form_state, $form_id) {
  $form['field_rate']['widget']['#ajax'] = array(
    'callback' =&gt; 'changeActualRate',
    'event' =&gt; 'change',
    'wrapper' =&gt; 'rates-wrapper'
  );
}

function changeActualRate(array &amp;$form, FormStateInterface $form_state) {
  // Get rate from taxonomy term
  $rate = $form_state-&gt;getValue('field_rate');
  if (!empty($rate)) {
    // Instantiate an AjaxResponse Object to return.
    $ajax_response = new AjaxResponse();

    $rate = taxonomy_term_load($rate[0]['target_id']);
    $cost = $rate-&gt;get('field_cost')-&gt;getValue();
    $cost = $cost[0]['value'];
    $ajax_response-&gt;addCommand(new InvokeCommand('#edit-field-actual-rate-0-value', 'val' , array($cost)));

    // Return the AjaxResponse Object.
    return $ajax_response;
  }
}


It's a pretty simple bit of functionality but it seems no Ajax gets initialised from inside the modal. Anyone have any ideas on how to initialise Ajax once the modal is open. Modals are being opened via links using class="use-ajax" data-dialog-type="modal".
It could be that your behaviors aren't processing the newly added modal elements because of an internal JS error.

I determined this because that was the problem discussed in this D7 answer:

How to trigger Drupal.attachBehaviors after successful Ajax