PDA

View Full Version : form defaults listeners specialkey not working with comboboxes



Malro
26 Sep 2012, 5:12 AM
Hello,

i want to add "ESC-cancel, ENTER-submit" handling to a formpanel.

so i added the following code to the form.


... = new Ext.FormPanel({
defaults:{
listeners: {
specialkey: function(item, e){

if (e.getKey() == e.ESC) {
win.destroy(); //close window
}
if (e.getKey() == e.ENTER) {
submit(); // submit form, callback handling
}
}
}
},
...

this is working fine, but not for comboboxes. --> nothing happens!

If i add the listeners explicit to any combobox --> it works!

Where is the clue?

sword-it
26 Sep 2012, 6:34 AM
Hi Malro,

Try the following code-


Ext.create('Ext.FormPanel', {
width: 500,
title: 'Parent Panel',
items: [{
xtype: 'textfield',
fieldLabel: 'Name',
listeners: {
specialkey: function(item, e) {
if (e.getKey() == e.TAB) {
alert('Tab key pressed')
}
}
}},
{
xtype: 'combo',
fieldLabel: 'Age',
store: ['15', '25', '35'],
listeners: {
specialkey: function(item, e) {
if (e.getKey() == e.ENTER) {
alert('Enter key pressed')
}
}
}}],
renderTo: Ext.getBody(),
});

Malro
26 Sep 2012, 10:05 AM
Hello,

i found a solution.

following is not working: (abstract)


formpanel
defaults:
listeners: specialkey
items:
textfield
combobox
listeners: afterrender (e.g.)
textfield


and this works:


formpanel
defaults:
listeners: specialkey
items:
textfield
combobox
textfield


if combobox has a listener (or still more) than formpanel-->defaults-->listeners will be ignored