PDA

View Full Version : Reference to function in button handler



andsm
28 Apr 2012, 12:24 AM
I have a very simple class that is descendant of FormPanel. It maintaines one text field and two buttons. Both buttons has handlers. But one of it inline handler and other like reference to a class function. When i create object of class inline handler fires properly, but by reference just not working. What the problem with code?


Ext.define("Test.TestForm",{
extend: 'Ext.form.FormPanel',
id: 'tform',
frame:true,
bodyStyle:'padding:5px 5px 0',
width: 600,
fieldDefaults:
{
labelAlign: 'top',
msgTarget: 'side'
},
items:
[
{ xtype:'textfield', fieldLabel: 'Name', name: 'last_name', style: "margin-left:10px;", anchor: "100%"},

],
buttons:
[
{ text: 'Test', scope: this, id: "test_data", handler: function() { alert("Test clicked"); } },
{ text: 'Send', id : "send", handler: this.SendTest }
],
SendTest : function () { alert("Sendtest called"); },
initComponent: function()
{
this.callParent();
}
});

waitingmyself
28 Apr 2012, 1:40 AM
maybe u can set the items on initComponent method

like
initComponent: function()
{
this.items =
[
{ xtype:'textfield', fieldLabel: 'Name', name: 'last_name', style: "margin-left:10px;", anchor: "100%"},

];
this.buttons =
[
{ text: 'Test', scope: this, id: "test_data", handler: function() { alert("Test clicked"); } },
{ text: 'Send', id : "send", handler: this.SendTest }
];
this.callParent();
}

andsm
28 Apr 2012, 1:48 AM
Thank you. Solution do job well!

In initComponent "this" exists, but in my case "this" is unexpected DomWindow class if use it outside initialize function.

waitingmyself
28 Apr 2012, 2:02 AM
in define method , the scope is window,i think;
because
window.SendTest = function() {
alert('sendtest');
};
is ok