3

I am creating a form with ajax submission in my Drupal custom form module.

When I click my submit button, I get the following error:

ajax: ajax.form.ajaxSubmit is not a function.

I am searching some blogs, try something like uninstalling lightbox2 module, color box module, etc. But again the same error is displayed.

How can fix this error?

Note: I installed Lightbox first, but after this error I uninstalled it again.

8
  • Do you have jquery update or ligthbox installed ?
    – niksmac
    May 20, 2013 at 3:15
  • I think you haven't included jquery form plugin . ajaxSubmit is not a core jquery function,
    – niksmac
    May 20, 2013 at 3:50
  • try drupal_add_library('system', 'drupal.form');
    – niksmac
    May 20, 2013 at 3:57
  • @NikhilM where I use this code
    – SKM
    May 20, 2013 at 3:58
  • in the init of the custom module or in the form page.
    – niksmac
    May 20, 2013 at 4:05

6 Answers 6

3

In Drupal 8:

   function YOURMODULENAME_page_attachments(array &$attachments) {
      global $base_url;
      $attachments['#attached']['library'][] = 'core/jquery.form';
      $attachments['#attached']['library'][] = 'core/drupal.ajax';
      $attachments['#attached']['library'][] = 'MODUL/login_module';
      $attachments['#attached']['drupalSettings']['LoginModuleBehavior']['base_url'] = $base_url;
    }
1

You'll need to include the Drupal ajax drupal_add_library('system', 'drupal.ajax');

2
  • 1
    where should i inculude this code
    – SKM
    May 20, 2013 at 3:58
  • not worked after include this code
    – SKM
    May 20, 2013 at 4:22
1

For future readers, you may need to include these libraries:

drupal_add_library('system', 'jquery.form');
drupal_add_library('system', 'drupal.ajax');

For example:

function MY_MODULE_my_form_id($form, &$form_state) {

  $form['#attached']['library'][] = array('system', 'jquery.form');
  $form['#attached']['library'][] = array('system', 'drupal.ajax');

}
1

Drupal 8

Drupal 8 does not include JS-libraries to pages automaticly. So most probably if you meet this error you need to attach 'drupal.ajax' library to your page (or form). Add something like this to your render array:

$form['#attached']['library'][] = 'drupal.ajax';
2
  • This question is about Drupal 7 (see "7" tag). So how does this answer the question? Jul 27, 2016 at 9:42
  • 2
    When searching about this issue with D8 we can find this page, it helped me, so it's accurate.
    – Kgaut
    Sep 13, 2016 at 9:56
1

Drupal 8

For people coming from Google and looking for a D8 solutions, try:

$form['#attached']['library'][] = 'core/drupal.ajax';
1
  • What is the correct solution? May 9, 2017 at 7:59
0

I disabled JavaScript aggregation in the performace config and it fixed my issues with this error in Drupal 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.