Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Fire select after store is loaded

  1. #1
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589

    Default Fire select after store is loaded

    Hi,

    I have a combo box with some values , when the combo box store is loaded i want to make a particular value selected depending on certain conditions, i used setValue and the combo box is shown what i assigned , i want to make the select event to work ,how can i do so

    below is code i used.


    Code:
    var domselect=[ 
                    { 
                        value: 1, 
                        title: 'Domain Name' 
                    }, { 
                        value: 2, 
                        title: 'Nameservers' 
                    }, { 
                        value: 3, 
                        title: 'User Profile' 
                    }, { 
                        value: 4, 
                        title: 'Domain Expires Within' 
                    } 
                ];
    
    
    var dommatches = new Ext.form.ComboBox({ 
                    id:'domaincriteria', 
                    hideLabel:true, 
                    height:23, 
                    store:  new Ext.data.JsonStore({ 
                        fields: ['value', 'title'], 
                        data: domselect 
                    }), 
                    editable: false, 
                    allowBlank:false, 
                    width:135, 
                    mode: 'local', 
                    triggerAction: 'all', 
                    emptyText: 'Select Type', 
                    selectOnFocus: true, 
                    hiddenName:'domainCondition', 
                    hiddenId:this.itemCount, 
                    valueField: 'value', 
                    displayField: 'title', 
                    labelSeparator: '', 
                    itemCls: 'floatLeft', 
                    tpl:templates.combo('title'), 
                    scope:this, 
                    listeners:{ 
                        render: { 
                            fn: function(){ 
                                dommatches.setValue(2); 
                                //dommatches.fireEvent( 'select', dommatches, dommatches.getAt(dommatches.selectedIndex ), dommatches.selectedIndex  ); 
     
                            }, 
                            scope: this 
                        } 
                    } 
                });
    when i alert the index its showing -1 i think its showing index of empty value. can i fire select after the value is set,

    can anyone provide me the code

    Thanks in advance

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    selectedIndex is only set when the value was selected from the dropdown list.

    I would recommend:
    Code:
    var record = combobox.findRecord('value', 2);
    var index = combobox.store.indexOf(record);
    combobox.onSelect(record, index);
    (onSelect will fire beforeselect and select event and call setValue)

  3. #3
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Dependent combos?

    I have overriden setValue to take a second parameter, fireSelectEvent as true or false, so that when programmatically setting the value, I can choose whether to inform dependent combos which might be listening for select.

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Might make a good FR.

  5. #5
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    V3 override:

    Code:
    Ext.override(Ext.form.ComboBox, {
        setValue : function(v, fireSelect){
            var text = v;
            if(this.valueField){
                var r = this.findRecord(this.valueField, v);
                if(r){
                    text = r.data[this.displayField];
                    if (fireSelect) {
                        this.fireEvent('select', this, r, this.store.indexOf(r));
                    }
                }else if(Ext.isDefined(this.valueNotFoundText)){
                    text = this.valueNotFoundText;
                }
            }
            this.lastSelectionText = text;
            if(this.hiddenField){
                this.hiddenField.value = v;
            }
            Ext.form.ComboBox.superclass.setValue.call(this, text);
            this.value = v;
            return this;
        }
    });

  6. #6
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589

    Default worked fine

    Hi,


    it just worked fine , thanks for your quick reply

  7. #7

    Default

    Doesn't seem like this sets the selectedIndex property. How would this be modified to set the selectedIndex? Thanks.

  8. #8

    Default

    Think I got it. Does this look right?

    Code:
        Ext.override(Ext.form.ComboBox, {
            setValue: function(v, fireSelect) {
                var text = v;
                if (this.valueField) {
                    var r = this.findRecord(this.valueField, v);
                    if (r) {
                        text = r.data[this.displayField];
                        if (fireSelect) {
                            var index = this.store.indexOf(r);
                            this.selectedIndex = index
                            this.fireEvent('select', this, r, index);
                        }
                    } else if (Ext.isDefined(this.valueNotFoundText)) {
                        text = this.valueNotFoundText;
                    }
                }
                this.lastSelectionText = text;
                if (this.hiddenField) {
                    this.hiddenField.value = v;
                }
                Ext.form.ComboBox.superclass.setValue.call(this, text);
                this.value = v;
                return this;
            }
        });

  9. #9
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Looks good.

  10. #10
    Sencha Premium Member
    Join Date
    Feb 2011
    Location
    Reston, VA
    Posts
    53

    Default

    Thanks. This works perfectly!

Page 1 of 2 12 LastLast

Posting Permissions

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