PDA

View Full Version : Specialkey listener on a form



AndreKR
18 May 2010, 8:34 AM
Hi,

when I attach a listener to a form like this:


xtype: 'form',
listeners: {
specialkey: function (f,e) {
if (e.getKey() == e.ENTER)
alert('lala');
}
}
}
Shouldn't the event be caught because it bubbles up from the fields? In fact, nothing happens.

Regards,
André

neenhouse
18 May 2010, 8:52 AM
xtype "form" represents Ext.form.FormPanel. Ext.form.FormPanel does not have a specialkey event, so the listener you are attaching is meaningless. You could implement your own key event I suppose, but wouldn't you rather attach listeners to the form controls themselves?

neenhouse
18 May 2010, 9:06 AM
You can implement a Ext.KeyMap config object via the config property "keys"

So:

{
xtype:'form',
keys:{
key: 13, // or Ext.EventObject.ENTER
fn: function(){ alert("Hello World"); },
scope: this
}
}