mik
mik

Reputation: 1575

ExtJs combobox stores loading and form

I have a problem with comboboxes on my form. The problem is that when I load form data (with form.loadRecord) sometimes comboboxes are empty even though I know that the model has the data.

When I look into Firebug I can see that the combobox stores are loaded after the record has been loaded. I thinks this is the reason – the combobox stores are loaded later then record is loaded.

This is how I set combobox stores:

    //All stores have autoload:true configuration.
    var possessionGroundsStore = Ext.create('path.to.store');
    var vehicleTypesStore = Ext.create('path.to.store');
    var usePurposesStore = Ext.create('path.to.store');
    this.editView = Ext.create('path.to.view');
    this.editView.getPossessionGroundsField().store = possessionGroundsStore;
    this.editView.getVehicleTypeIdComboBox().store = vehicleTypesStore;
    this.editView.getUsePurposeField().store = usePurposesStore;

    //later
    this.editView.loadRecord(record);

Is there a common way to solve this problem?

The only way I can see now is to use store.load callbacks in every combobox store and then execute loadRecord after all stores were loaded, but it seems complex.

Any help?

UPDATE: When form.loadRecord is called it internally calls field.setValue(). So, the point is: combobox store have to be populated before setValue is called. If the store is not loaded you will see valueField instead of displayField.

Upvotes: 0

Views: 8003

Answers (1)

egerardus
egerardus

Reputation: 11486

The default config for comboboxes will trigger a store load when they get expanded for the first time after being created.

That will happen for any combobox unless you give it a queryMode: 'local' config. In other words the default combobox config almost always completes loading it's store after the component is created. For that reason, it seems strange to me that your combos are having a hard time with being loaded too late, maybe they are being loaded too early with autoLoad: true

However, I don't run into the same problem you have because I usually set-up my comboboxes with queryMode: 'local' and pre-load the stores for them right at the app initialization stage. I do that because my combo stores are usually all reference stores that could get used in many different views in my app. I don't recreate the store when I create a combo component, I just get a reference to the already existing and loaded reference store with Ext.getStore('ComboStoreId'). You could try setting up your app like that.

If you don't want to do that, you could also try removing the autoLoad: true config from your combo stores, then call yourComboStore.load() after you call loadRecord.

Upvotes: 5

Related Questions