I have a custom module that is adding a new field in the form in hook_form_alter().

In my hook_form_alter() I have

function mymod_form_alter(&$form, &$form_state, $form_id) {
     $form['complaint']['complaint_category'] = array(
        '#type' => 'select',
        '#title' => t('Complaint'),
        '#options' => myfuc(),
        '#required' => TRUE,
        '#empty_option' => t('Choose complaint category'),
        '#default_value' => $selected_complaint_category,
        '#ajax' => array(
          'callback' => 'mymod_complaint_dependent_dropdown_callback',
          'wrapper' => 'dropdown-complaint-remark',

If I add a break point in my code in the function mymod_complaint_dependent_dropdown_callback() it is not triggered. Another element in the form has a #ajaxsetting and a break point on it works.

In the UI no spinner is added to the page. So it looks to me like the ajax event is not being registered. Any ideas?

  • can you also post the working code ? is this also in the hook_form_FORMID_alter ?
    – rémy
    Jun 17, 2015 at 10:07

1 Answer 1


You could try adding an 'event' item to the ajax array in your FAPI code. The form needs to know when to trigger the ajax callback. The FAPI documentation says you don't have to specify it explicitly but try 'event' => 'change', and see if that works for you. Since you are not specifying it, perhaps the default one that Drupal uses is not right for a select type.

See https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#ajax_event

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.