PDA

View Full Version : Specialkey event triggered before select event for combobox



Spenna
31 Aug 2013, 4:48 AM
Hi all.

I have a combobox with a list of products (local store), and have configured it so that you type the name to filter the list, press enter to select the record if found. If enter is pressed with no records found i want to create a new record with the currently entered text.

The problem is that the specialkey-event is triggered before the select-event, so unless i create extra code to check the store again for the entered value inside the specialkey-listener, a new record is created, and select-event is never triggered.

It works if i add a short 'delay' to the specialkey-listener, but this gives another problem as the parent form is then submitted.

Hopefully someone can point me in the proper direction, thankful for any reply.



listeners: {
specialkey: {
// delay: 100, // Tiny delay to ensure potential select event has triggered first
fn: function(combo, e) {
var val;

if (e.getKey() === e.ENTER) {
e.stopPropagation(); // no bubbling of this event (to prevent parent form save)
val = combo.getRawValue();

if (val) {

// create new record from val
// add it to store

combo.reset();
combo.focus(true);
}
}
}
},
select: function(combo, records, eOpts) {

var product = records.pop() || null;

// create new record from product
// add it to store

combo.reset();
combo.focus(true);

}
}

Spenna
5 Sep 2013, 3:09 PM
Anyone? I'm really hoping to solve a problem for real users here..
If my post is unclear, please say - i'll do my best to explain.

Thankful for any response

ettavolt
6 Sep 2013, 2:30 AM
If you want to create record on ENTER, you will need to override onExpand method of combo to change enter handler of combo.listKeyNav. Beware: this in those methods refs boundlist, that's why, I believe, they chose to define methods in closure.
However, I state that better approach is to choose a different moment for record creation: form submit, blur or anything else. Of course, this depends on your business logic.

Spenna
8 Sep 2013, 7:50 AM
The record is just created to be used in a form subsequently, after the enter is hit. The real problem is the ordering of events. If there is a way to prevent the specialkey-event from bubbling, even when the 'delay' option is set, i would be home free.

Maybe someone have a better approach - a short re-cap of what i want to achieve:

I have a combo with is configured with a store and its designed for remotely filtering. If filter-value is not found, user should have an easy way to create a new record with this value. (For the not-found text, i've put 'Press <enter> to create a new record with this value', which brings up a modal form prepopulated with this name).

ettavolt
9 Sep 2013, 12:17 AM
Only override of onExpand method (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox-method-onExpand) will help, because select-on-enter handler listens to same event, but is attached later, then BaseField's fireKey.