Problem
Since the introduction of active-link.js (#1979468: ".active" from linkGenerator(), l() and theme_links() forces an upper limit of per-page caching for all content containing links), whenever an ajax enabled form element executes commands, the following error occurs:
DrupalBehaviorError: attach ; l: context.querySelectorAll is not a function (active-link.js, row 48)
This is the interested line:
var activeLinks = context.querySelectorAll(selectors.join(','));
Here, the attach function rightly assumes that context is a plain object (as implied by the documentation of Drupal.attachBehaviors), so there is nothing wrong with it.
The error originates from ajax.js, where Drupal.attachBehaviors and Drupal.detachBehaviors are called passing the this.form variable as context, which is a jQuery object. The variable is created in the Drupal.ajax constructor:
if (this.element.form) {
this.form = $(this.element.form);
}
Note that the bug has always been there, but attach functions almost always perform something like var $context = $(context)
, so it was never exposed.
Proposed resolution
Adjust all calls to Drupal.attachBehaviors and Drupal.detachBehaviors in ajax.js so that the plain dom object of the form is passed. Rename this.form
throughout the script to this.$form
so it's clear that the variable represents a jQuery object.
Comment | File | Size | Author |
---|---|---|---|
#2 | ajaxjs-form-context-2168171-2.patch | 4.8 KB | peterpoe |
#1 | ajaxjs-form-context-2168171-1.patch | 5.22 KB | peterpoe |
Comments
Comment #1
peterpoe CreditAttribution: peterpoe commentedComment #2
peterpoe CreditAttribution: peterpoe commentedFound a $(this.form) in an event that should remain $(this.form).
Comment #4
nod_Oh! yes please.
Tested and works. code is much better than what I have in #2168233: tabledrag javascript does not update weight fields when dragging rows for ajax.js
Comment #6
nod_Whatever testbot.
Comment #7
nod_parent has been rolled back, put this in new patch.