Topic: Ajax in FA - Analysis (WIP)
There appears to be a lack of documentation (even in the wiki) regarding Ajax as used in FrontAccounting. Before making a wiki page for it, those in the know can contribute to this thread from where it will be distilled into the wiki.
If on the change of value of any FA form element, some ajax work needs to be done (like other form elements getting updated or some function being executed), then a $_POST array element needs to be set and sent.
The $_POST array element must bear a name that embeds the ajax requesting element's name attribute as seen in Lines 300 to 307 in the function list_updated($name) in includes/ui/ui_lists.inc file:
/*
Helper function.
Returns true if selector $name is subject to update.
*/
function list_updated($name)
{
return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
}
Hence if the ajax requesting form element is stock_id then the hidden form elemet that is sent over for an ajax call in FA would either be:
$_POST['_stock_id_update']
or
$_POST['_stock_id_button']
for the function list_updated($name) to trigger the ajax response.
To get the response inside a target form element, it's name attribute is passed on like $Ajax->activate('price').
This is seen for example in lines 506-511 in sales/includes/ui/sales_order_ui.inc:
if (list_updated('stock_id')) {
$Ajax->activate('price');
$Ajax->activate('units');
$Ajax->activate('qty');
$Ajax->activate('line_total');
}
All functions that assist ajax responses are in includes\ui\ui_lists.inc.