This topic is locked
[SOLVED]

 JavaScript: Callback function for the "Save all" Button on List Pages

8/14/2012 5:27:14 PM
PHPRunner General questions
T
Tricause author

Hello,
PHPRunner allows the use of inline add/edit of records on the list pages. Once a record is being added or edited through this manner, the button "Save all" (with id "saveall_edit1") appears and, when pressed, calls some PHP script which saves the values to the table.
I currently am using custom buttons that will allow the user to proceed to another page, but for the convenience of the user, I would like to save all inline adds/edits when these buttons are pressed so that the user will not have to press "Save all" or accidentally lose all inline-edits. I know through jQuery I can use



$("#saveall_edit1").click()



to save the records; however, adding a jQuery callback function, e.g.



$("saveall_edit1").click(

function () { /* some code */ }

);



will not work appropriately, because the callback function there is not synchronous with the call used to update the database. I could use a time delay, and that has worked, but that is not an elegant solution and may not always work.
I would like to be able to, through some method, save all inline edits and then proceed with some arbitrary JavaScript code. Is this possible?
Thank you for any input.

C
cgphp 8/14/2012

A quick solution:

jQuery.ajaxSetup({async:false});

$("#saveall_edit1").click();

jQuery.ajaxSetup({async:true});
/*execute the remaining code*/



Keep in mind that doing an AJAX call with async:false will cause the browser to hang until the AJAX request completes.

T
Tricause author 8/15/2012



A quick solution:

jQuery.ajaxSetup({async:false});

$("#saveall_edit1").click();

jQuery.ajaxSetup({async:true});
/*execute the remaining code*/



Keep in mind that doing an AJAX call with async:false will cause the browser to hang until the AJAX request completes.


Hi Cristian,
It appears that this still does not work, as the code after the click still appears to be executed before the record is saved.
Jake