PDA

View Full Version : ComboBox event for selecting an item



brunofin
10 Jul 2014, 7:06 AM
I need to find the correct event that is fired every time an item is selected in a single-selection type of ComboBox.
The documentation can be a little bit unclear about this. Here's a link for reference:

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.form.field.ComboBox
(http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.form.field.ComboBox)
I tried select (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.form.field.ComboBox-event-select) and change (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.form.field.Field-event-change), with the following results:

select is fired just once, when I select an item for the first time, and it's not fired ever again when selecting other items. It works as expected when navigating with the keyboard instead of mouse;
change does not fire at all.
ExtJS version used is 4.2.0.

Sabareesh
15 Jul 2014, 3:14 AM
select should work fine , try this

var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});


// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners : {
select : function(cmb){
Ext.Msg.alert('value' , 'The selected value id is ' +cmb.value);
}
}

Thanks
Sabareesh.

greg.barry
15 Jul 2014, 1:06 PM
Sabareesh is correct. I created a fiddle of both the change and select listeners firing.

https://fiddle.sencha.com/#fiddle/7nf

Thanks!
Greg