Results 1 to 6 of 6

Thread: how to auto setValue on COMBO on the foreign key val ?

  1. #1
    Sencha User
    Join Date
    Oct 2010

    Default how to auto setValue on COMBO on the foreign key val ?

    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{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{
      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;'load',function(store){
    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 ?

  2. #2
    Sencha User vishalnnsingh's Avatar
    Join Date
    Sep 2010
    Kolkata, India


    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.
    I Meet Challenge with Excitement & My Only Gossip is Love

  3. #3
    Sencha User
    Join Date
    Oct 2010


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

  4. #4
    Sencha User
    Join Date
    Oct 2010


    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... :-)

  5. #5
    Ext JS Premium Member devtig's Avatar
    Join Date
    Jan 2010
    Rotterdam, The Netherlands


    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:
    Christiaan Westerbeek @ Devotis
    Contact me for help with Ext JS, Node JS, FireBase, AngularJS and Javascript in general. Email me or find me at AirPair to connect.

  6. #6
    Sencha User
    Join Date
    Oct 2010


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

Similar Threads

  1. Combo.setValue
    By nawal106 in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 16 Feb 2010, 5:23 AM
  2. [SOLVED] How to filter a grid or a data store on a foreign key
    By lpastor in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 29 Aug 2009, 2:43 PM
  3. Replies: 1
    Last Post: 3 Aug 2009, 1:13 PM
  4. combo setValue
    By nadeemshafi9 in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 3 Jul 2009, 9:30 AM
  5. Rows with the same foreign key (innoDB) won't show in grid
    By Dr. Flink in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 15 Sep 2008, 10:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts