View Full Version : tabitem.onloaded?

1 Nov 2006, 1:34 PM

I've been looking for a solution to a seemingly easy problem with tabPanels:

I have tabs, which are connected to an ajax call handled by the updateManager. The content returned is a form which needs to be filled with values from Javascript Arrays. The question now is, how can I trigger a script in order to fill in the values after the form is completely loaded?

I have been looking for an easy solution, without change to the core scripts...here is one of my attempts

mytab.onActivate.subscribe(initFormLoad, updater, true);

which triggers my js function before completing loading. That way, I cannot getElementById(formID) and am therefore unable to fill in the values.

Any help is very much appreciated.


1 Nov 2006, 10:05 PM
Take a look at UpdateManager 'update' event. It is called when the update has completed. You can also pass a callback to the update() method that will be called when loading is complete.

2 Nov 2006, 12:40 AM
This is where that issue that I've been boring you about might come up Jack.

If ajaxrules's whole form hasn't been rendered, then his postprocessing is not going to be right. It does take a while to render things. Before I added my code in, that 10 millisec delay wasn't enough to allow all the scripts to be rendered, so the script loading wasn't adding them all to the document's header.

I did some experiments counting the size of the getElementsByTagName("*") Array from the updated element after various delays. You could really see it incrementally rendering and adding elements.

I really think there should be a way to fire an event onRendered.

(Sorry to harp on so much when I know you're working away like crazy on about 50 different enhancements!)

2 Nov 2006, 1:36 AM
To be honest, I don't mind adding it in. I just don't want to support it. :) There are bound to be some issues and I think there are less complicated ways to do it. Personally, I never have had the problem because I never load scripts through XHR requests. Is that a must?

One other idea on how it can be done: YAHOO.util.Event.onAvailable for the id you want after the update call? You could even add an id to the script element.

2 Nov 2006, 1:58 AM
Yes, I can see your dilemma not wanting to support complex additions.

It's not only scripts you have to wait for. In ajaxrules's scenario, he's processing form input elements which he needs to all be present.

As you say, if the loading code knows an ID to wait for, it can use Yahoo.util.Event.onAvailable.

2 Nov 2006, 2:54 PM
Thanks for your hint Jack! Knowledge is power

I managed to work it out this way:

I have the following included in the initTabs function

var initOnAfterLoad = function(){
YAHOO.util.Event.onAvailable("trigger"+ ID ,initForm)

mytabXY.onActivate.subscribe(initOnAfterLoad, updater, true);

The trigger + ID refers to a span elementID rigth after the form, that way at least my form is loaded (the initForm and all other scripts are inserted above my form). So far, I haven't noticed any problems Animal is referring to. Things seem to work fine. :shock:

That opens a whole new range of possibilities in my scenario, since I am implementing existing components which build on javascript calls after loading, which would be a pain in the neck to redo.

2 Nov 2006, 3:04 PM
Sweet. Thanks for letting me know the results.