Results 1 to 2 of 2

Thread: Prepopulating combo box in Ext JS 5

  1. #1

    Default Prepopulating combo box in Ext JS 5

    Hi - I am relatively new to Ext JS and am facing an issue as follows -

    I have a requirement where if there is a value in the cookie, then the combo box should have the cookie value pre populated or else it should be pre populated with the first value in the store.
    This combo box is part of a pop up which will be displayed based on a business rule. The code for the condition and pop up is present in the controller. Pop up is a modal window. The issue I'm facing is that I'm not able to pre populate the combo box on load of the pop up. The store of this combo box gets populated from Web service.
    I have tried the below methods for pre population in the listener:
    1) afterrender : function (){ this. setValue(value) }
    2) afterrender : function(combo) { combo.select()}

    Any help is appreciated.

    Thanks.

  2. #2
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    769
    Answers
    38

    Default

    Create custom combo which will support remoteText and remoteValue - this will work for cookie values only.

    PHP Code:
    setRemoteValue: function (valuename) {
        
    this.setValue(value);
        
    this.setRemoteText(name);
    },

    setRemoteText: function (text) {
        var 
    me this;

        if (
    me.value && text) {
            var 
    me.findRecord(me.valueFieldme.value);

            if (!
    r) {
                var 
    recordData = {};

                if (
    me.store.fields && me.store.fields.keys) {
                    for (var 
    0me.store.fields.keys.lengthi++) {
                        
    recordData[me.store.fields.keys[i]] = "";
                    }
                }

                
    recordData[me.valueField] = me.value;
                
    recordData[me.displayField] = text;

                
    me.displayTplData = [recordData];
                
    me.setRawValue(me.getDisplayValue());
            } else {
                
    r.set(me.displayFieldtext);
                
    me.setValue(me.value);
            }
        }
    }, 
    However to select first value in store, you need wait till the store is loaded. So simply use load event and set first value:

    PHP Code:
    store.on('load', function() {
        
    combo.select(store.getAt(0)); //select expect model
    }); 
    store.load(); 

Tags for this Thread

Posting Permissions

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