Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts

    scriptaculous: adding inplaceeditors after ajax.updater

    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':

    Code:
    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:

    Code:
    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:

    Code:
    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!

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    nevermind, I think I have this figured out...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •