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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peterpoe’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
5.22 KB
peterpoe’s picture

Found a $(this.form) in an event that should remain $(this.form).

The last submitted patch, 1: ajaxjs-form-context-2168171-1.patch, failed testing.

nod_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +JavaScript
Related issues: +#2168233: tabledrag javascript does not update weight fields when dragging rows

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

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: ajaxjs-form-context-2168171-2.patch, failed testing.

nod_’s picture

Status: Needs work » Reviewed & tested by the community

Whatever testbot.

nod_’s picture

parent has been rolled back, put this in new patch.