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.