onchange – change 3 fields

Questionsonchange – change 3 fields
Caroline asked 8 years ago

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);

}

1 Answers
Abu Ghufran answered 8 years ago

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.

Your Answer

9 + 12 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?