Form Ajax not working when rendered from Ajax callback I am trying to load a Drupal form through an AJAX callback when the user selects an option from a select list. The code used to generate this form as follows:

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['dashboard_list'] = array(
    '#title' =&gt; t('Select Dashboard:'),
    '#type' =&gt; 'select',
    '#ajax' =&gt; array(
        'callback' =&gt; 'Drupal\dashboard\Controller\DashboardController::OnPanelSwitch',
        'effect' =&gt; 'fade',
        'event' =&gt; 'change',
        'progress' =&gt; array(
            'type' =&gt; 'throbber',
            'message' =&gt; NULL,
            ),
        ),

   );
return $form;
}


Inside of OnPanelSwitch(), which is called when the user selects an option from the list. I am using the renderer service to get the form's HTML and then inserting the form into a div.

 public static function OnPanelSwitch(array &amp;$form, FormStateInterface $form_state) {
    $ajax_response = new AjaxResponse();

    $AddChartForm = \Drupal::formBuilder()-&gt;getForm('Drupal\dashboard\Form\AddChartForm');
$AddChartFormHTML =\Drupal::service('renderer')-&gt;render($AddChartForm);


    $ajax_response-&gt;addCommand(new HtmlCommand('#formarea', $AddChartFormHTML));

    return $ajax_response;


}

This HTML is then inserted into a DIV in the page. The form being loaded via AJAX is built in the following manner and contains a single select list: 

public function buildForm(array $form, FormStateInterface $form_state) {    
   $form['query_type'] = array(
      '#title' =&gt; t('Query Type'),
      '#title_display' =&gt; 'invisible',
      '#type' =&gt; 'select',
      '#options' =&gt; array(t('Chart'), t('Table')),
      '#prefix' =&gt; '&lt;div class="floatLeft"',
      '#suffix' =&gt; '&lt;/div&gt;',
      '#ajax' =&gt; array(
          'callback' =&gt; 'Drupal\dashboard\Controller\DashboardController::OnQueryFieldChange',
          'effect' =&gt; 'fade',
          'event' =&gt; 'change',
          'progress' =&gt; array(
              'type' =&gt; NULL,
              'message' =&gt; NULL,
              ),
          ),

  );
return $form
}


The OnQueryFieldChange() callback is not being called when this form is being loaded via the initial AJAX call. If I load this form without AJAX through the twig template everything works correctly. So it seems to be an issue of the form being loaded via AJAX.

From my research it seems like I might have todo something with Drupal Behaviors to enable AJAX for this form? Any guidance would be really helpful.
I have fixed the issue I was having by just returning the render array of the form rather than trying to get the form's HTML. So my AJAX callback function now looks something like this: 

public static function OnPanelSwitch(array &amp;$form, FormStateInterface $form_state) {

   $ajax_response = new AjaxResponse();

   $AddChartForm = \Drupal::formBuilder()-&gt;getForm('Drupal\dashboard\Form\AddChartForm');

   $ajax_response-&gt;addCommand(new HtmlCommand('#formarea', $AddChartForm));

return $ajax_response;