Dependent selects in Ctools modal I am experiencing a rather odd problem in Drupal 7.

I have a form in Ctools modal. It should contain 2 dependent select boxes (among other fields). I've done this dozen times on regular forms, but i can't make it work in the Ctools Modal form. Modal pops up, all the fields are there, all the counties are in the first select box, but it looks like it's not even reaching the ajax callback when a county is selected, so no dealer are returned. When I hard code the county id, dealers from that county show as expected.

My code is similar to the following:

menu item:

$items['modal-data/%ctools_js'] = array(
  'page callback' =&gt; 'core_modal_form',
  'page arguments' =&gt; array(1),
  'access arguments' =&gt; array('access content'),
  'delivery callback' =&gt; 'ajax_deliver',
  'type' =&gt; MENU_CALLBACK,


);

general modal handling:

function ni_core_modal_form($js) {

// Check whether js is enabled.
if ($js) {

  // Include ctools modal plugin.
  ctools_include('ajax');
  ctools_include('modal');

  // Create notify entity
  $form_state = array(
    'title' =&gt; 'Contact dealer',
    'ajax' =&gt; TRUE,
  );

  $commands = ctools_modal_form_wrapper('contact_dealer_modal_form', $form_state);

// If form was submitted.
  if (!empty($form_state['executed'])) {

    $commands[] = ajax_command_replace('#modal-content', theme_status_messages(['display' =&gt; 'status']));

  }

  print ajax_render($commands);
  drupal_exit();
 }
}


The form in ctools modal:

function contact_dealer_modal_form($form, &amp;$form_state) {

   // get all counties
  $counties = get_dealer_counties_list();

  // Check for the selected county
  $county = isset($form_state['values']['county']) ? $form_state['values']['county'] : key($counties);

  // get dealer for selected county
  $dealers = get_dealer_select_list($county);

  $form['wrapper'] = [
    '#type' =&gt; 'container',
    '#attributes' =&gt; ['class' =&gt; ['contact-dealer-form-wrapper']],
  ];

  $form['wrapper']['county'] = [
    '#type' =&gt; 'select',
    '#title' =&gt; t('Select your county'),
    '#options' =&gt; $counties,
    '#ajax' =&gt; array(
      'callback' =&gt; '_county_dealer_callback',
      'wrapper' =&gt; 'dealer-replace',
    ),
  ];

  $form['wrapper']['dealer'] = [
    '#type' =&gt; 'select',
    '#title' =&gt; t('Select your dealer'),
    '#options' =&gt; $dealers,
    '#default_value' =&gt; 0,
    '#prefix' =&gt; '&lt;div id="dealer-replace"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  ];

  $form['submit'] = [
    '#type' =&gt; 'submit',
    '#attributes' =&gt; ['class' =&gt; ['btn btn-primary'] ],
    '#value' =&gt; t('Contact'),
  ];

  return $form;
}


ajax callback:

function _county_dealer_callback($form, &amp;$form_state) {

  return $form['wrapper']['dealer'];
}


I will highly appreciate any suggestion!
Well, as it turns out, the problem was that the form definition was in an .inc file and Ctools couldn't find it. The solution was to simply put the form definition, submit handler and ajax callback for select in a .module file.