If the hint javascript gets run multiple times, additional hint input boxes are added each time. For example, we are using CTools on our site to produce dialog boxes. When the link for this is clicked, the CTools box appears, but the hint JS is run through again, causing extra boxes. The attached patch ensures that hint boxes are only added on the first run.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 952126-multiple-hints-added-7.patch | 545 bytes | aron novak |
| #4 | 952126-hint-p1-D6.patch | 1.85 KB | kndr |
| hint-multiple-hints.patch | 873 bytes | james.williams |
Comments
Comment #1
quicksketchWhile this would be a good idea to add, I should note that the most likely actual cause of the problem is some module or JavaScript not attaching behaviors properly after an AJAX request. The "content" variable should only contain the new part of the page, in which Hint's behaviors have not already been applied. What's probably happening is that the entire document is getting behaviors re-applied, meaning the browser is doing a lot of unnecessary work. Anyway, you're right that Hint should provide a safety-net against this happening, but at the same time it's revealing that some module is not calling Drupal.attachBehaviors() correctly, because it shouldn't be a problem to begin with.
Comment #2
steven jones commentedsubscribe.
Comment #3
steven jones commentedActually according to: http://drupal.org/node/205296 - Overview of JavaScript, AJAX, AHAH API:
So using a class to ensure an element is not processed twice is actually the standard way to handle this.
Patch looks good to me.
Comment #4
kndrIdea is very good. Solution is needed but there are some problems with patch:
I have different approach, which should work in any situation. I am checking if placeholder exists, and if it doesn't, I place it in DOM. It prevents from adding placeholder more than once, when attachBehaviors() is called many times. I am attaching the patch.
Comment #5
hibersh commentedduplicated elements be added when use form #ajax
Thanks @james.williams. The patch works well for me
Comment #6
trigop commented@james.williams, the patch works well for me. Good job.
Comment #7
aron novakA bit simplier patch.