Results 1 to 4 of 4

Thread: Remote combo setValue as part of form load

  1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    8

    Default Remote combo setValue as part of form load

    Hi guys,

    I'm having some problems while setting the value of a combo inside a form. In fact the issue is visible when the request for load the combo ends later than the request for load the form, in this case the load form action try to set the combo value before combo load is finished, resulting in a "inocuous set" since there is no values in the combo store.

    Is there an standard way to avoid this effect?

    I have avoid this over the time linking load requests success events, and showing the window in the last level:
    Code:
    panel.getForm().load({
        url: 'api/user/21',
        method: 'GET',
        success: function(form, action) {
            combo.getStore().load({
                callback: function() {
                    combo.setValue(action.result.data.mycombo.value);
                }
            });
        }
    });

  2. #2
    Sencha User lucasguaru's Avatar
    Join Date
    May 2011
    Location
    Guaruj, Brazil
    Posts
    77

    Default

    I had this problem too.
    In other words, my problem was that I had stores that was needed to be loaded before I load the form values.
    I had treestores to read before too so I would select some elements when the form was loaded.
    I create a method to I pass all the stores. This method counts the stores I need to read before the form.
    For each store, this method add a single listener 'load' and associate it to another method which counts the loaded stores.
    If the stores loaded are the same as the stores added (to load), I load the form.
    The good thing about this, you don't need to code inside the load of all your stores (or combobox store).
    The stores can load simutanely, and only after that, the form loads and the values are set.
    Code:
    countStoresToLoad : 0,
    countStoresLoaded : 0,
    
    addStoreToLoad : function(store) {
        this.countStoresToLoad++;
        store.on('load', this.addCountStoresToLoad, this, {single : true});
    },
    
    addStoresToLoad : function(stores) {
        if (Ext.isArray(stores)) {
            Ext.each(stores, this.addStoreToLoad, this);
        } else {
            this.addStoreToLoad(stores);
        }
    },
    
    addCountStoresToLoad : function(store) {
        this.countStoresLoaded++;
        if (this.countStoresLoaded == this.countStoresToLoad) {
            this.loadRecord();
        }
    },
    I have to change my code to be clear so you'll have to test.
    I hope it works for you too.
    Let me know if you need any help.

  3. #3
    Sencha User
    Join Date
    Jan 2010
    Posts
    8

    Default

    Hi,

    Thanks for your reply. I have found a clearest way to do it:
    Code:
    Ext.define('AsyncSafeComboBox', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.safecombo',
        setValue: function(value, doSelect) {
            if(this.store.loading){
                this.store.on('load', this.setValue.createDelegate(this, arguments));
                return;
            }
            this.callParent(arguments);
        }
    });
    By using safecombo, the setValue method is called when combo store has been already loaded.

    Antonio.

  4. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    22

    Default

    This looks like an interesting idea but for ExtJS 4 setValue() function would probably need to be modified as follows:

    Code:
    setValue: function(value, doSelect) {
            if (this.store.loading){
                this.store.on('load', Ext.Function.pass(this.setValue, arguments, this), this, {single:true, scope:this});
                return;
            }
            this.callParent(arguments);
        }

    Quote Originally Posted by amuniz View Post
    Hi,

    Thanks for your reply. I have found a clearest way to do it:
    Code:
    Ext.define('AsyncSafeComboBox', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.safecombo',
        setValue: function(value, doSelect) {
            if(this.store.loading){
                this.store.on('load', this.setValue.createDelegate(this, arguments));
                return;
            }
            this.callParent(arguments);
        }
    });
    By using safecombo, the setValue method is called when combo store has been already loaded.

    Antonio.

Posting Permissions

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