PDA

View Full Version : How to stop ComboBox trigger on store.add(record)



cmeans
15 Nov 2012, 7:45 AM
ExtJS v4.1.1a.

I have a ComboBox with a local store that's working fine, except that when I programmatically add a record to it's store, the "trigger" appears to be firing (causing the drop down list to app and show the entry I just added).

Is there a config setting to suppress this behaviour or am I possibly doing something else wrong?

Thanks.

-Chris

greg.barry
15 Nov 2012, 6:56 PM
Chris,

I made a small test case and I can't seem to recreate what you have described. The record is successfully added to the store and the combobox remains the same. In other words, it does not appear to trigger.



Ext.onReady(function () {
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"PF", "name":"Pink Floyd"}
]
});


Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});


Ext.create('Ext.Button', {
text: 'Press Me',
renderTo: Ext.getBody(),
listeners: {
click: function(){
states.add({"abbr":"LZ", "name":"Led Zeppelin"});
}
}
});
});


Thanks!
Greg

cmeans
17 Nov 2012, 12:38 PM
Hi Greg,

It appears you are correct.

What I wasn't seeing is that the act of typing in the combo box was triggering it to "open up" the drop down list...it's just not so visible when there's nothing there. However, because the store.add call adds an entry, it's then displayed in the already open list.

I do want the list displayed if there's a matching entry, but I'd like to suppress it if I have to add one.

Any suggestions on the best approach?

Thanks for your help.

-Chris