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.

Comments

quicksketch’s picture

While 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.

steven jones’s picture

subscribe.

steven jones’s picture

Status: Needs review » Reviewed & tested by the community

Actually according to: http://drupal.org/node/205296 - Overview of JavaScript, AJAX, AHAH API:

The context variable that is passed in can often give you a better idea of what DOM element is being processed, but it is not a sure way to know if you are processing something again.

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.

kndr’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.85 KB

Idea is very good. Solution is needed but there are some problems with patch:

  1. It doesn't apply to hint-6.x-1.2
  2. This method doesn't work in some, specific situations (I am surprised, too). I am using menu_minipanels module, which copies content of minipanel and bind this copy to qTip. I have some textfields with hints inside this copied minipanel. Inside my code, I call attachBehaviors() for this copied content. Class 'hint-processed' is copied too and Drupal behaviors aren't attached to 'hint-processed' element once more. Unfortunatelly, event bindings (onFocus and onBlur) for hint placeholder is done inside $.hint(), which is not called. Hints don't work at all.

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.

hibersh’s picture

Version: 6.x-1.2 » 7.x-1.2

duplicated elements be added when use form #ajax
Thanks @james.williams. The patch works well for me

trigop’s picture

@james.williams, the patch works well for me. Good job.

aron novak’s picture

StatusFileSize
new545 bytes

A bit simplier patch.