Threaded View

  1. #1
    Sencha User
    Join Date
    Aug 2009
    Posts
    480
    Vote Rating
    1
    plalx has a spectacular aura about plalx has a spectacular aura about

      0  

    Lightbulb ComboBox.setValue (remote/local)

    ComboBox.setValue (remote/local)


    Here's a piece of code that allows you not to ever think about the combobox's store state when dealing with setValue() with a local or remote combobox. Calling setValue multiple times on a remote combobox will work as well, it will automatically load the value from the server first (by sending the value as the [valueField] param to the server) and then select it. Calling setValue() on a remote combobox will also make sure that any active requests are cancelled before proceeding. In addition, the callbacks won't execute if the combobox has been destroyed.

    Code:
     
    Ext.override(Ext.form.ComboBox, {
        setValue: Ext.form.ComboBox.prototype.setValue.createInterceptor(function(v, loadRecord) {
            loadRecord = !(loadRecord === false);
            if (!this.isDestroyed && loadRecord) {
                var cbo = this,
                    store = cbo.store,
                    isLocalMode = cbo.mode === 'local',
                    vField = cbo.valueField,
                    callback = function(rec, options, success) {
                        if (success && cbo.store) {
                            cbo.setValue(v, false);
                        }
                    };
                
                if (isLocalMode && !Ext.isDefined(store.totalLength)) {
                    store.on({
                        'load': callback,
                        scope: cbo,
                        single: true
                    });
                    
                    if (!store.autoLoad) {
                        store.load();
                    }
                    return false;
                } 
                else if (!isLocalMode) {
                    var rec = cbo.findRecord(vField, v);
                    
                    if (!rec) {
                        var readRequest = store.proxy.activeRequest.read,
                            params = {};
                        
                        if (readRequest) {
                            readRequest.conn.abort();
                        }
                        
                        params[vField] = v;
                        store.load({
                            callback: callback,
                            params: params
                        });
                        return false;
                    }
                }
            }
        })
    });
    Last edited by plalx; 27 May 2011 at 11:04 AM. Reason: Refactored with createInterceptor

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."