PDA

View Full Version : Reset combobox when forceSelection = true and user can edit the combobox



crazy_in_love
13 Nov 2013, 8:53 PM
I have a combobox which have a config 'forceSelection: true'. User can edit the combobox, for example: type in arbitrary text, then immediately click the reset button to reset the combobox but the combobox won't reset to its original value. How could I fix this?

Here's my code to describe the problem:

var states = Ext.create('Ext.data.Store', {

fields: ['abbr', 'name'],

data : [

{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});

Ext.create('Ext.container.Container', {

layout: 'hbox',

margin: '50',

renderTo: Ext.getBody(),

items: [
{
xtype: 'combobox',
margin: '0 10 0 0',
fieldLabel: 'Choose State',
forceSelection: true,
store: states,
queryMode: 'local',
value: 'AL',
displayField: 'name',
valueField: 'abbr'

},
{
xtype: 'button',
text: 'reset',
handler: function () {
this.up('container').down('combobox').reset();
}
}
]
});
});

tobiu
14 Nov 2013, 5:33 AM
reset will change the value to the one that you initially specified with the value config.
in your case Alabama.

if you want an empty value instead, change your code like this:


//this.up('container').down('combobox').reset();
this.up('container').down('combobox').setValue();

crazy_in_love
14 Nov 2013, 6:54 PM
Thanks tobiu, but your answer don't solve my problem.

It's weird that when I reset the combobox with :

this.up('container').down('combobox').reset();

or when I set its value to 'Alabama' with:

this.up('container').down('combobox').setValue('Alabama');

The combobox both reset to blank. I expect it to reset to my original value 'Alabama'. Is it a bug of Ext 4.1?