1. #1
    Ext User
    Join Date
    Oct 2008
    Posts
    4
    Vote Rating
    0
    ziggurat is on a distinguished road

      0  

    Default (Newbie) Remote load combo options and select an item

    (Newbie) Remote load combo options and select an item


    I am creating a form for some data edition, so i am using a Reader to retrieve and fill the form data. One of the form components is a ComboBox, and i need to load the options of this combo remotely so i am using this code to load the combo options:

    Code:
    store = new Ext.data.JsonStore({
    url: 'some_url', root: 'editors', fields: ['field1', 'field2']
    })
    But i also need that one of the combo options be selected (this selected id would be retreived with the reader). The problem is that, the combo is loaded only when i press it, and in that moment the reader has already filled the data into the form.

    1) How can i achieve this? or
    2) Is there a way of filling and selecting the combo using the form reader instead of using a different ajax loader for the combo?

    Thanks in advance!

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,498
    Vote Rating
    46
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Does this help?

    Code:
    Ext.override(Ext.form.ComboBox, {
        setValue : function(v){
    //      Store not loaded yet? Set value when it *is* loaded.
            if (this.store.getCount() == 0) {
                this.store.on('load', this.setValue.createDelegate(this, [v]), null, {single: true});
                return;
            }
            var text = v;
            if(this.valueField){
                var r = this.findRecord(this.valueField, v);
                if(r){
                    text = r.data[this.displayField];
                }else if(this.valueNotFoundText !== undefined){
                    text = this.valueNotFoundText;
                }
            }
            this.lastSelectionText = text;
            if(this.hiddenField){
                this.hiddenField.value = v;
            }
            Ext.form.ComboBox.superclass.setValue.call(this, text);
            this.value = v;
        }
    });
    The addition in red defers the setValue call until after the next load.

  3. #3
    Ext User
    Join Date
    Oct 2008
    Posts
    4
    Vote Rating
    0
    ziggurat is on a distinguished road

      0  

    Default


    I dont quite understand your solution , so the setValue is delayed until the combobox store is loaded, but how do this relate to the reader i have on the form? I mean, where should i retreive the value that should be selected on the combo?

  4. #4
    Ext User crxtech's Avatar
    Join Date
    Nov 2007
    Location
    Baltimore, MD
    Posts
    87
    Vote Rating
    0
    crxtech is on a distinguished road

      0  

    Default Thanks!!!

    Thanks!!!


    Thanks Animal. Code works great!

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    87
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Quote Originally Posted by Animal View Post
    The addition in red defers the setValue call until after the next load.
    I modified your code a bit to avoid an infinite wait on a loaded but empty store:
    Code:
    Ext.override(Ext.form.ComboBox, {
    	setValue : function(v){
    		if(this.mode == 'remote' && this.store.totalLength === undefined){
    			this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true});
    			if(this.store.lastOptions === null){
    				this.store.load();
    			}
    			return;
    		}
    		var text = v;
    		if(this.valueField){
    			var r = this.findRecord(this.valueField, v);
    			if(r){
    				text = r.data[this.displayField];
    			}else if(this.valueNotFoundText !== undefined){
    				text = this.valueNotFoundText;
    			}
    		}
    		this.lastSelectionText = text;
    		if(this.hiddenField){
    			this.hiddenField.value = v;
    		}
    		Ext.form.ComboBox.superclass.setValue.call(this, text);
    		this.value = v;
    	}
    });

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,498
    Vote Rating
    46
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Condor, do you think your code should be made a Feature Request?

    This issue keeps coming up.

  7. #7
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    87
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Quote Originally Posted by Animal View Post
    Condor, do you think your code should be made a Feature Request?
    Definitely!

    Could you create the feature request (it's your idea after all)?

  8. #8

  9. #9
    Sencha User
    Join Date
    Jul 2009
    Posts
    12
    Vote Rating
    0
    Henrik Rutzou is on a distinguished road

      0  

    Default This works great, but ...

    This works great, but ...


    May I suggest a little add on to the feature request:

    When you use the drop down or search facility the system automatically adds

    query, limit and start parameters to limit the servers responce

    it would be nice if the initial load added a value parameter so the server dosn't have to return the whole datastore but just the record for the value that's currently is in the field.

    Regards
    Henrik

  10. #10
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    87
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    That is already in the feature request (use this override and specify a valueParam).

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..."