PDA

View Full Version : scriptaculous: adding inplaceeditors after ajax.updater


cmancone
03-07-2009, 10:44 PM
I'm using ajax.updater to update a div, and the updated div contains a number of divs which I want to enable an inplaceeditor on. I don't know the "good" way to do this, but I found a way that largely works with one irritating hitch. I have a function that just adds inplaceeditors to all divs that have ids prefixed with 'task':


function add_editors()
{
var divs = document.getElementsByTagName("div");
for(var i=0; i < divs.length; i++)
{
var id = divs[i].id.toString();
var pre = id.substr( 0, 4 );
if ( pre == 'task' )
{
new Ajax.InPlaceEditor(id, 'process_ajax.php?upd_task=true&id=' +id);
}
}
}


Very hack and slash, I know. But it works. I call this function on page load and I get lots of inplaceeditors. Then, I have a function which updates the div that contains all these inplaceeditors, and the updated content is exactly the same as before, but with a couple extra divs:


function add_task()
{
new Ajax.Updater( 'proj_id', 'process_ajax.php?new_task=proj_id', { method: 'get' });
add_editors();
}


This code, unfortunately, doesn't work. The ajax.updater works, but none of the divs are inplaceeditors. To add to the confusion though if I make a small change:


function add_task()
{
new Ajax.Updater( 'proj_id', 'process_ajax.php?new_task=proj_id', { method: 'get' });
window.alert('test');
add_editors();
}


Everything works! I get an alert, and everything turns into inplaceeditors. If I remove the window.alert(), nothing works. Similarly, if I add a window.alert as the first action in the add_editors() function, everything works! Why in the world window.alert() fixes things, I have no clue.

Any suggestions would be greatly appreciated. Also, if you can point out the proper way to do this I'm all ears. I tried adding the 'evalscripts: true' option to the ajax.updater, and passed the lines to add inplaceeditors inside the returrned content, but that didn't work at all :( Thanks in advanced!

cmancone
03-10-2009, 03:01 AM
nevermind, I think I have this figured out...