vaske
vaske

Reputation: 9542

Ext combobox select after store reload doesn't work properly

Here is my combobox configuration

{
    xtype : 'combo',
    fieldLabel : 'Select Field',
    displayField : 'field_name',
    valueField : 'field_id',
    id : 'fields_combo_id',
    store: new Ext.data.JsonStore({
         proxy : new Ext.data.HttpProxy({url:eyefind.config.DATA_RETRIEVAL, method:'GET'}),
         baseParams: { subject: 'fields' },
         root: 'data',
         id: 'field_id', 
         fields: ['field_name'],
         autoload: true
     }),

    labelStyle : 'font-weight:bold; width:100px',
    triggerAction : 'all',
    clearFilterOnReset : false,
    mode : 'local'
 }

I load the store in an external function in this way:

        .....
        var comboFields = Ext.getCmp('fields_combo_id');
        comboFields.store.load(); 
        comboFields.setValue(selectedFieldId);
        .....

And so far selectedFieldId has been set but in the visible part I see a value instead of displayText, the store looks fine and I have the value:displayValue pair properly set there.

Do I miss something or do I have to use some other functionality for this part?

My version of Ext is 3.2.0.

Upvotes: 4

Views: 2543

Answers (2)

MMT
MMT

Reputation: 2216

Try the following code.

var selectedFieldValue = Ext.getCmp('fields_combo_id').getRawValue();
var selectedFieldId    = Ext.getCmp('fields_combo_id').getValue();
comboFields.setValue(selectedFieldId,selectedFieldValue);

Upvotes: 0

Egy Mohammad Erdin
Egy Mohammad Erdin

Reputation: 3413

You set valuefield : 'field_id', but there is no field_id in store's fields,

{
    xtype : 'combo',
    fieldLabel : 'Select Field',
    displayField : 'field_name',
    valueField : 'field_id', //This 'field_id' must be in store fields too.
    id : 'fields_combo_id',
    store: new Ext.data.JsonStore({
        proxy : new Ext.data.HttpProxy({url:eyefind.config.DATA_RETRIEVAL, method:'GET'}),
        baseParams: { subject: 'fields' },
        root: 'data',
        id: 'field_id', //This id is just for the store, not the record data.
        fields: ['field_id','field_name'], // here, i add `field_id`
        autoload: true // This should be autoLoad, remember JavaScript is case sensitive.
    }),

    labelStyle : 'font-weight:bold; width:100px',
    triggerAction : 'all',
    clearFilterOnReset : false,
    mode : 'local'
}

And also, why do you set autoLoad : true if you load it again in your external function?

EDIT

When I run comboFields.setValue(id);, in which my id is assign to one of the field id, it works, and I see displayfield on my combo (no need to dropdown first). But, if, in your case, your combo item has been highlighted, I guess it's because of the version. Unfortunately I tested it in Ext 3.3.0.

Upvotes: 3

Related Questions