PDA

View Full Version : Problem with Extend



sofway
13 Oct 2010, 6:13 AM
Hi,
i have a formpanel that im extending and when i add a handler to the buttons of the form, i cant get the form to fire the submit method.




App.clientes.panelCreate = Ext.extend(Ext.form.FormPanel, {

autoHeight: true,
frame:true,

initComponent: function(){
Ext.apply(this,{
items: [
{
xtype: 'textfield'
}
],
buttons: [
{
text: 'Guardar',
handler: function(){
this.getForm().submit(); // this line fire the error saying that this.getForm does not exist
}
},
{
text: 'Cancelar',
}
]
});
App.clientes.panelCreate.superclass.initComponent.apply(this, arguments);
}
});
var nuevo = new App.clientes.panelCreate();

The error shows when i hit the button guardar
How can i get the form component?

Thanks

plalx
13 Oct 2010, 6:18 AM
You need to provide the right scope (object to which the keywork this will point to) to your handler function. By default, 'this' will refer to the button in the button click handler function, and obviously, Ext.Button.getForm() method does not exist. See below how to provide the correct scope (the form scope).



{
text: 'Guardar',
handler: function(){
this.getForm().submit(); // this line fire the error saying that this.getForm does not exist
},
scope: this
}

Condor
13 Oct 2010, 6:18 AM
In the button handler 'this' will be the button.

You have to add scope:this to the button to override the value of 'this'.

sofway
13 Oct 2010, 6:22 AM
It works!
Thanks