View Full Version : how to auto setValue on COMBO on the foreign key val ?

12 Jan 2011, 3:10 AM
So, I have (pays) countries table and then (city) cities table (pays.pays_iden=city.pays_iden)... I edit city record . There, normal, i have a combo... With Countries list (valuField need to be equal to city pays_iden value from database, which is the foreign key in city for pays). So, I have :

// the reader for my current city record
var evRd=new Ext.data.JsonReader({idProperty: 'city_iden',root: 'arrVals',
fields: [
{name: 'city_iden', type:'int'},
{name: 'paysIden', type:'int', mapping:'pays_iden'},
{name: 'city_nume', type: 'string'}
// then the store for the combo with the linked country...
var paysCboSt=new Ext.data.JsonStore({
url: 'dbgt/getPays.php?o=pays_nume&d=ASC&i='+pId+'',method:'POST',
idProperty: 'pays_iden',successProperty:'success',root: 'arrVals',
fields: [

// then in my form, except the cityID and cityNAME i have :
{fieldLabel:'Country', id:'pays_iden', name:'pays_iden',
xtype:'combo', store:paysCboSt, valueField:'pays_iden', displayField:'pays_nume',
autoSelect:true,forceSelection:true, triggerAction:'all',editable:false,
var me=this;
I so have a hidden field in the form called paysIden. And I need that the form autoSelect this value on load. So what must I call instead :
I can also delete this field (the fake hidden paysIden, because the real one is pays_iden and is the combo !) but I don't know how to call this value from my json response (because i set it there) :

1. how setValue in combo valueField the hidden fake paysIden value ? or
2. how setValue in combo the json selId value which come by the json of combo ?

12 Jan 2011, 3:50 AM
Use the select event in the country combo, which resets the city field on country change and afte the country is selected pass the id to the server and reload your city store.

12 Jan 2011, 4:06 AM
thanks for answer. but the country WILL not be re-selected ! i needed, on LOAD, auto...
i have two possibilities. please read my thread. I am sure the data that I already have in it must be enough.
1. i have a fake paysIden, a hidden input which contains the city record pays_iden correct value (ex: 2).
2. i have also the json for countries (pays) list to put in combo and here i have a selId field (which contains same value as the hidden fake paysIden), ex:2
see the and of my first post. I got the idea, but I cannot guess all the details for it. Use select event... Means, I think to put a listener on combo... But this will not resets city... alone, I think... "after the contry is load"... which of them ? the combo ? the id of the country id the hidden fake id field ? or in the returned json ? "pass the id to the server and reload city store" I hope that is "pass the id as param to the store, and then reload it from server ?" and why from there... this is over my newbie capacities. thanks anyway for advice.
but, thanks to help me, please :-)

12 Jan 2011, 5:33 AM
I learn, learn, learn... And I cannot change my opinion (3 months now) about ExtJS from "amazing" !
Not nice to be rookie :-)... But here are all the excitement ! When know all... Become bored !
Like they said on a Discovery advertising : "If we have all the answers, there will be nothing left to discover. So, ignorance is bliss"
And I think even ignorance is not only bliss, but is also bless ! :-)
So for my thread problem... I am sure that there are something in ExtJS stronger than the function below... But not find (within 1- hours...) :-( And because I really must go quickly ahead, I think I re-invented somehow the wheel... :-)
So, I call this after window loads... And if this can help others with similar problems, feel free to use it. I also use a similar function for showing a mask until a form is populated...

function loadComboDelayed(form,fieldFrom,comboTo){
if( !document.getElementById(fieldFrom) ||
document.getElementById(fieldFrom).value=='' ||
}so, still awaiting for a pure extjs elegant solution... :-)

12 Jan 2011, 1:08 PM
Wow, you managed to fit in one small piece of code:
1. misuse the asynchronous way of callbacks with a delay
2. unnecessary use of Ext.getCmp
3. unnecessary use of document.getElementById

Read here:

The asynchronous way:

url: 'ajax_demo/sample.json',
success: function(response, opts) {
//do something with the server response that
//arrives some time later.
var obj = Ext.decode(response.responseText);
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);

But if you're just starting with Ext JS you better start reading here:

13 Jan 2011, 6:02 AM
I threat all my Ajax request Exactly in your way. But here is form.load()... Whatever, really thanks for your asnwer.
c pm.. :-)