Javascript behaviours problem

JeebsUK - June 16, 2009 - 10:48

Dear all,

I was wondering if anyone has an answer to the following question I have posted on devshed:

http://forums.devshed.com/javascript-development-115/document-ready-func...

Any help would be greatly appreciated.

Cheers.

Drupal.behaviors.myModuleBehavior

marcvangend - June 16, 2009 - 13:26

Drupal is the answer to your prayers! Instead of using $(document).ready, define a new drupal behavior. See http://api.drupal.org/api/file/developer/topics/javascript_startup_guide....

Thanks but...

JeebsUK - June 16, 2009 - 13:29

I do not need a new behaviour, just to re-run the initial behaviour of the tabledrag when my table has been created in my ajax call.

Further to the previous

JeebsUK - June 17, 2009 - 09:38

Further to the previous discussion, I think that if I call drupal.attachBehaviors(); in the load event of my jquery ui tabs, it would re-initialise all the drupal behaviors, including tabledrag and draggable, but this does not seem to work. Does anyone have any further ideas or explanations as to why this doesnt work?

Which jQuery version are you

marcvangend - June 17, 2009 - 12:25

Which jQuery version are you using? With version 1.2.6, events can only be bound to existing elements. If the table you want to be draggable is loaded with ajax, that might cause problems. Maybe it would help to install jQuery 1.3.2 using jQuery Update (http://drupal.org/project/jquery_update) and use the new 'live evenst' feature of that release (see http://docs.jquery.com/Release:jQuery_1.3#Live_Events).

PS. I assume you already know this page: http://api.drupal.org/api/function/drupal_add_tabledrag/6.

1.2.6

JeebsUK - June 18, 2009 - 16:40

Hi there,

We are using 1.2.6. I'm not really in a position to upgrade at the moment because I'm not sure what that would break, we use quite a lot of jquery on our site. The live events do sound very interesting though.

As you correctly stated, the table I want to be draggable is loaded into the ajax tab, so the initialisation of all draggable objects has already taken place well before the table is loaded. This is why I thought called drupal.attachBehaviors (either with no parameters or specifying the table id) might help, but I have had no luck with this method.

maybe...

marcvangend - June 18, 2009 - 19:51

I'm not 100% sure, but I'm afraid that you will not be able to do this with jQuery 1.2.6. There is one possible workaround I can think of (not sure if it works). Maybe you can put an empty table on the tab (just the table tags with the correct ID), attach the tabledrag to it and insert the table contents (tr's and td's) in the table.

Please let me know when you're able to solve this.

 
 

Drupal is a registered trademark of Dries Buytaert.