Results 1 to 5 of 5

Thread: Unable to access combobox store

  1. #1

    Default Unable to access combobox store

    Hi , Please let me know whats wrong with following combobox code. I am unable to access its store in setValue() function (overridden function).
    I could see the options list loaded when I Click on Selection, But unable to access its store when it is loaded initially. this.store returning undefined.

    Code:
    var comboPlans = new Ext.form.ComboBox({
    	name :'premPlanNo', id:'premPlanNo',lazyRender:true,typeAhead: true,
    	triggerAction: 'all',   mode:'remote',	 allowBlank:false, 
    	hiddenName:'premPlanNoId',
        	store: new Ext.data.JsonStore({
            			id:'plansStore', 	
            			root:'plans',
            	 		fields: [
    						{name:'value', mapping:'value'},
    						{name:'meaning', mapping:'meaning'}
            			],
            			url :contextPath + "/reportGenerator?"+operation+"=getPremiumPlans"
            			
        	}),
        	
    		valueField: 'value',  	displayField: 'meaning',  	fieldLabel :'Premium Plan',	anchor :'95%'
    });

  2. #2
    Ext JS Premium Member saJoshua's Avatar
    Join Date
    Nov 2007
    Location
    Sydney
    Posts
    526

    Default

    I can't see your usage of "this.store", but I can advise you to be careful with the "this" keyword unless you know exactly what you're doing with it. This is because "this" refers to the parent context of wherever you're using it.

    Try using : comboPlans.store instead.

  3. #3

    Default

    Thanks for quick response. Here is the overridden setValue() function that i am using for combobox. this.store which is marked in below code is causing undefined exception

    Code:
    Ext.override(Ext.form.ComboBox, {
    	    setValue: function(v){
    			
    	        if(this.mode == 'remote' && !Ext.isDefined(this.store.totalLength)){
    	            this.store.on('load', function(){
    	                var rec = this.findRecord(this.valueField, v);
    	                this.setValue(rec ? rec.get(this.valueField) : '');
    	            }, this, { 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;
    	    }
    	});

  4. #4
    Ext JS Premium Member saJoshua's Avatar
    Join Date
    Nov 2007
    Location
    Sydney
    Posts
    526

    Default

    ok, try check if there is a store?

    Code:
    Ext.override(Ext.form.ComboBox, {
    	    setValue: function(v){
    			
    	        if(this.mode == 'remote' && this.store && !Ext.isDefined(this.store.totalLength)){
    	            this.store.on('load', function(){
    	                var rec = this.findRecord(this.valueField, v);
    	                this.setValue(rec ? rec.get(this.valueField) : '');
    	            }, this, { single: true});
    	            //if(this.store.lastOptions === null){
    	                this.store.load();
    	            //}
    	            return;
    	        }
    	        var text = v;
    	   .. etc...
    May I ask what you're overriding the combo's setValue for?

  5. #5

    Default

    Thanks man,

    My code works without any further changes, I am not sure why. I just configured two more comboboxes with similar requirement and tried executing and it simply works. some thing strange..

    By the way to answer your question.. I have a grid on left hand side and trying to update the right hand side Form when I select a row in the grid. Where as when I load values from grid to form, the combo box is only setting value instead of displayValue from the list. Iam overriding the combobox setValue() to set the Display Value from the list based on the value.

    Thanks.
    Nagadev

Posting Permissions

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