1

I have two Extjs Comboboxes

var cb1 = new Ext.form.ComboBox({
    fieldLabel: 'Combobox1',
    width: 100,
    listeners:{
         scope: this,
         'select': this.reset
    }
});
var cb2 = new Ext.form.ComboBox({
    fieldLabel: 'Combobox2',
    width: 100,
    baseParams: { loadInitial: true, cb1Val: this.cb1.getValue() } // Here I want to get selected value of cb1
    listeners:{
         scope: this,
         'select': this.reset
    }
});

I am using this.cb1.getValue() to get selected value of cb1 but I am getting blank value here.

Can anyone tell me what I am doing wrong here.

1 Answer 1

0

I think combo 2 is not able to get value of combo 1 as its not loaded while you are calling its value in baseParams. I would recommend this approach in your case -

    var cb1 = new Ext.form.ComboBox({
        fieldLabel: 'Combobox1',
        width: 100,
        **id : "combo_1",**  // ID property added 
        listeners:{
             scope: this,
             'select': this.reset
   } });

// Previous code 
...

    listeners : {
        select : function(combo, rec, rind) {
             var combo2_val = Ext.getCmp("id_of_combo_1").getValue();
    }

Here, on the select renderer of second combo, the value of first should be set in combo2_val. To be more precise, you can also set default value for combo 1. Instead of using ID, you can directly use variable cb1 directly.

Hope this should give you a way.

1
  • But I want to pass selected value of cb1 to the base Parameter of cb2 when cb2 is loaded. The above approach sets it in select listener of cb2. Sep 27, 2013 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.