nav
nav

Reputation: 158

Extjs ComboBox setValue

I've a combobox (e.g. change owner). When a user selects a value of the combobox, I prompt user if he is sure to change owner. If he clicks on 'Yes', I update the record in database. All works fine till this point.

Now, if the user selects a value and clicks 'No' on prompt (after selecting value from combo). The combo retains the new value and does not bring it back to the old value. I tried setValue/Load etc but none is setting back the old value on the click on No.

My Code looks like this

        combo = new Ext.form.ComboBox({
                        store: storeJson,
                        xtype: 'combo',
                        displayField:'name',
                        valueField: 'id',
                        mode: 'local',
                        id: 'privateTo',
                        name: 'privateTo',
                        typeAhead: false,
                        triggerAction: 'all',
                        lazyRender: true,
                        editable:false,
                        listeners: {select: changeOwner}
                    }); 

var changeOwner = function(combo, record, index) {              

            Ext.MessageBox.confirm("Change Owner","Are you sure you want to change owner?",function(btn){
            if (btn == "yes") {
                Ext.Ajax.request({
                   url: 'somUrl',
                   method: 'PATCH',
                   success: function(result, request) { 
                        msg('Owner changed', 'Owner changed');
                   },
                   failure: function(result, request) { 
                        Ext.MessageBox.alert('Error', "Unable to change owner");
                        Ext.getCmp("customizationGrid").getStore().reload();
                   }
                });
            } else {
                var d = Ext.getCmp('customizationGrid').getSelectionModel().selection;
                var rec = combo.store.getById(d.record.json.privateTo);
                Ext.getCmp("privateTo").setValue(rec.data.name);

            }
            });
        }

Upvotes: 1

Views: 11312

Answers (2)

Snehal Masne
Snehal Masne

Reputation: 3429

Just remove the else { ... } block, it should take care of NO. :-)

Upvotes: 1

Allie
Allie

Reputation: 1179

The last selected value of your combo is already present in the select handler.

You can simply do :

...

} else {   
    combo.setValue(combo.startValue);
}

Upvotes: 0

Related Questions