3

After updating module webform_paymethod_select I noticed that Ajax on webforms stopped working. I was unable to edit any existing webforms or create new ones. This happens when JS Aggregation is enabled. Clearing caches did not help.

Console shows two error messages:

TypeError: D.ajax is undefined
  var beforeSerialize = D.ajax.prototype.beforeSerialize;

TypeError: Drupal.ajax is undefined
  Drupal.ajax.prototype.commands['getBlock'] = function(ajax, response, status) {

The first error is coming from jQuery update and the second one is coming from the boxes module. Disabling boxes module worked for me but it left an important part of my site broken.

I believe the reason is that Ajax is unable to load before boxes requires it. After this Ajax just does not load at all.

If anybody can help me out, I would appreciate it.

EDIT:

I couldn't quite figure out how to get Ajax to load before everything. I tried changing its weight in drupal_add_js() and modifying hook_boot() to get it to load first. This seemed dangerous as i couldn't guarantee that it would only apply to the pages i needed Ajax to be first in. I then turned to figuring out how to encapsulate the boxes modules' JavaScript code that was throwing this error. I noticed that the code was being encapsulated with the following:

(function ($) {
  ..
})(jQuery);

Drupal suggests using :

(function ($) {
  // All your code here
}(jQuery));

That didn't work either, so i used the following instead and this made the error go away (except for the error jQuery Update is throwing):

jQuery(function($){
  ..
});

I am now able to edit existing webforms. I don't really understand why this worked, so if anybody can provide some insight i would appreciate it.

0

1 Answer 1

1

It could help.

add php function:

use Drupal\Core\Ajax\AjaxResponse;

Class AnyClass extends FormBase {

public function buildForm(array $form, FormStateInterface $form_state) {

/**
 * Running the library drupal core ajax
 */
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';

}

}

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.