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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | js-use_context-630424-8-D6.patch | 4.13 KB | DeFr |
| #2 | DRUPAL-6--14-jscontext.patch | 4.13 KB | raspberryman |
| #1 | DRUPAL-6--14-jscontext.patch | 4.04 KB | raspberryman |
Comments
Comment #1
raspberryman commentedThis patch hit the issues I was facing (multiple node forms, each with "Unlimited" CCK fields and autocomplete fields, loaded via AHAH at separate times.
Comment #2
raspberryman commentedSome backwards compatibility, in case other module wrappers are outside of the context.
Comment #3
aaron commentedahah! 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.
Comment #5
_tychris commentedI'm the same problem here http://drupal.org/node/417810#comment-3446096
Comment #6
nyl_auster commented#2: DRUPAL-6--14-jscontext.patch queued for re-testing.
Comment #8
DeFr commentedLooks 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
Comment #9
kenorb commentedMarked: #417810: Autocomplete fields in popup don't work as duplicate.
Comment #10
nyl_auster commentedWhy 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 ?
Comment #11
galaxor commentedDeFr, don't forget ahah.js:27.
- $('#'+ base).addClass('ahah-processed');
+ $('#'+ base, context).addClass('ahah-processed');
Comment #12
nod_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.