Hi!
In my add-in form, I have a dropdown list of my clients. When I choose a client, I want to update 3 fields automatically. A drop-down list and 2 text fields. Is it possible?
I tried with "onchange", "update_fields", "callback" and nothing works.
"onchange" => array( "sql"=>"SELECT asso.id as k, ref.nom as v, c.codez, c.adresse FROM asso_clients_equipements asso INNER JOIN ref_equipements ref ON ref.id=asso.fk_id_equipement INNER JOIN clients c ON c.id=asso.fk_id_client WHERE fk_id_client = '{fk_id_client}'",
"callback"=>"update_info"
function update_info(data)
{
o = jQuery('.ui-search-toolbar select[name=fk_id_asso_client_equip]').get();
o.event = 'onload'; fx_get_dropdown(o,'fk_id_asso_client_equip',1);
// fill dropdown 1 based on row data
o = jQuery('select[name=fk_id_asso_client_equip]').get();
o.event = 'onload'; fx_get_dropdown(o,'fk_id_asso_client_equip');
jQuery("input[name=codez].FormElement").val(data[0].codez);
jQuery("input[name=codez].editable").val(data[0].codez);
jQuery("input[name=adresse].FormElement").val(data[0].adresse);
jQuery("input[name=adresse].editable").val(data[0].adresse);
}
onupdate and callback combination should work here.
Following lines should fill the 2 fields names where $col["name"] are codez and adresse.
jQuery("input[name=codez].FormElement").val(data[0].codez);
jQuery("input[name=codez].editable").val(data[0].codez);
jQuery("input[name=adresse].FormElement").val(data[0].adresse);
jQuery("input[name=adresse].editable").val(data[0].adresse);
Dropdown down should be filled in same manner.
Other code like:
o = jQuery('.ui-search-toolbar select[name=fk_id_asso_client_equip]').get();
o.event = 'onload'; fx_get_dropdown(o,'fk_id_asso_client_equip',1);
// fill dropdown 1 based on row data
o = jQuery('select[name=fk_id_asso_client_equip]').get();
o.event = 'onload'; fx_get_dropdown(o,'fk_id_asso_client_equip');
is not really required and used when you need dependent dropdown.
You can refer demos/dropdown-callback.php code for working demo.