PDA

View Full Version : 'this' Scope Enter Keyboard Navigation question



karthik085
19 Jul 2010, 3:36 PM
Hi,
I have a FormPanel - code below. On pressing the enter key, the form should get submitted. In the handler function, if I I use 'this' like "this.getForm()....", it does not work. However, if I replace, that with Ext.getCmp('test'), i.e. (Ext.getCmp('test')).getForm() - it works.

I understand - pressing the key causes a different scope and hence, 'this' does not correspond to FormPanel, but to KeyNav or some other class. Are there workaround so 'this' can be used?



TestPanel = function(){
TestPanel.superclass.constructor.call(this, {
id:'test',
...
items: [{
xtype: 'textfield',
name: 'q',
fieldLabel: 'q'
}, {
xtype: 'button',
text: 'Submit',
handler: this.onSubmit ,
scope: this
}],
keys: [
{ key: [Ext.EventObject.ENTER], handler: this.onSubmit }
]
});
};

Ext.extend(TestPanel, Ext.FormPanel, {
onSubmit: function(){
alert(this.getForm().findField('q').getValue());
}
});