Re: [bug] autocomplete broken by Prototype library
Just wanted to throw my support in for yched's fix. I think its essential that Drupal fully support popular libraries like prototype. As is we've lost a lot of brilliant minds to frameworks like rails. From the standpoint of bringing in more experienced developers to work on drupal, offering full support of libraries like phototype is a high priority. Thanks for figuring this out wched... I hadn't realized the problem had been prototype and autocomplete bumping heads. -Nick Lewis http://nicklewis.smartcampaigns.com yched wrote:
Issue status update for http://drupal.org/node/47557 Post a follow up: http://drupal.org/project/comments/add/47557
Project: Drupal Version: cvs Component: forms system Category: bug reports Priority: normal Assigned to: Anonymous Reported by: yched Updated by: yched Status: patch (code needs review)
Well, the issue I'm dealing with did affect Firefox (1.5/win) - I didn't check for IE or other browsers.
The patch has been tested to work on both FF and IE6.
As it is outlined in the posts you link to, we're not talking about a drupal bug, but rather about allowing the use of a very useful yet quite intrusive external lib.
I'm aware that a 'won't fix' would be tempting for core devs here, Then again, the workaround is so simple...
yched
Previous comments: ------------------------------------------------------------------------
Thu, 02 Feb 2006 11:40:05 +0000 : yched
Example : go to a node submission / edition form and type a new author for the node.
According to the FireBug extension for Firefox, an error is raised on line 259 of autocomplete.js :
matches[i].split is not a function (seen on Firefox 1.5, btw. Untested on other browsers)
------------------------------------------------------------------------
Thu, 02 Feb 2006 12:34:44 +0000 : jjeff
Interesting. I will look into this.
-Jeff
------------------------------------------------------------------------
Sun, 12 Mar 2006 20:00:16 +0000 : yched
Changing title and project : In fact, the bug is not related to the s/p ajax module itself, but to the presence of the Prototype library itself.
I'll try to use the JS debugger to see what's happening really...
------------------------------------------------------------------------
Sun, 12 Mar 2006 21:39:59 +0000 : yched
Attachment: http://drupal.org/files/issues/autocomplete.js_2.patch (1010 bytes)
Okay, here's what I (sort of) understood :
Prototype adds a lot of methods (iterators, helper functions...) to a lot of objects (including arrays)
A side effect is that when you walk an array with a loop like : for (i in myArray) { aalert(i +' : '+ myArray[i]); } you first catch the "regular' elements of the array, and then you catch these Prototype-added methods.
So the (simplified) code in autocomplete.js : for (i in matches) { matches[i] = matches[i].split('|'); } raises an error when it calls the (non existing) 'split' method of these extra elements (which are functions and not strings)
I just replaced for (i in matches) { with for (i=0; i<matches.length; i++) {
I'm no JS expert, so there might be more elegant workarounds, but this does the trick.
(It seems to me that no other drupal js code is impacted, but that might need double-checking)
------------------------------------------------------------------------
Sun, 12 Mar 2006 21:42:46 +0000 : yched
forgot to update the status
------------------------------------------------------------------------
Sun, 12 Mar 2006 22:20:25 +0000 : markus_petrux
I was also a "victim" of prototype.js' method of overriding javascript core objects (Array in this case) with one of my phpBB MODs: http://forums.phpmix.org/viewtopic.php?t=1014
As far as we saw in that topic, the problem seems to affect MSIE only (a browser bug maybe).
I do not use prototype.js myself, but I believe yched's fix would workaround the problem.
participants (1)
-
Nick Lewis