There are several key selectors in Drupal core javascript files that do not include a specific jQuery context (ie, $(selector, context)).

While everything seems to work fine as is, life as a developer becomes harder and harder, with more and more bugs, the deeper we get into ajax/ahah complexity with our client's projects.

Here are three places (I am sure there are more) that I needed for a recent project:

/* ahah.js */
149:   var wrapper = $(this.wrapper);

/* autocomplete.js */
13:    var input = $('#' + this.id.substr(0, this.id.length - 13))

/* tabledrag.js */
19:      $('#' + base).filter(':not(.tabledrag-processed)').each(function() {

In my case, I had mytype_node_form loading in several places on one page, at runtime and via ajax. This results in several attachBehavior calls to these three files. However, since we are dealing with the same forms and IDs, the above statements didn't work. My solution is to do a ton of form_alters on the IDs, but this impacts so many CCK field types and other forms that it would be great if Drupal javascript was a little more forgiving.

Comments

raspberryman’s picture

StatusFileSize
new4.04 KB

This patch hit the issues I was facing (multiple node forms, each with "Unlimited" CCK fields and autocomplete fields, loaded via AHAH at separate times.

raspberryman’s picture

StatusFileSize
new4.13 KB

Some backwards compatibility, in case other module wrappers are outside of the context.

aaron’s picture

Version: 6.14 » 6.17
Status: Active » Needs review

ahah! that explains all the frustration i've had around making ahah work with elements loaded after the page load through ajax. drupal needs to eat its own dogfood.

Status: Needs review » Needs work

The last submitted patch, DRUPAL-6--14-jscontext.patch, failed testing.

_tychris’s picture

nyl_auster’s picture

Status: Needs work » Needs review

#2: DRUPAL-6--14-jscontext.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, DRUPAL-6--14-jscontext.patch, failed testing.

DeFr’s picture

Version: 6.17 » 6.x-dev
StatusFileSize
new4.13 KB

Looks like patch in #2 was hand-edited and thus didn't apply, here's a reroll.

Having quickly glanced at what might need to be fixed in D7 first:
- the tabledrag.js hunk is already in D7, so that's fine
- the autocomplete.js hunk applies pretty much as is, the problem's still there
- the ahah.js hunks needs to be ported to ajax.js

kenorb’s picture

nyl_auster’s picture

Why the last patch status is marked as "ignored" ?
It seems to me that http://drupal.org/node/417810 works like a charm concerning autocomplete.js, and that this is tiny but effective change to apply to all those js from Drupal.

This issues has been opened one year ago. How can i help to make this commited ?

galaxor’s picture

DeFr, don't forget ahah.js:27.
- $('#'+ base).addClass('ahah-processed');
+ $('#'+ base, context).addClass('ahah-processed');

nod_’s picture

Status: Needs work » Closed (won't fix)

ID selectors don't/shouldn't need context. And well, there is a patch if someone needs it, I'm not sure things like that would get committed to D6. Feel free to reopen if you still feel strongly about this.