PDA

View Full Version : Form ans Scope Problem



mvbaffa
9 Oct 2010, 7:02 AM
Hi,

I suppose I have a problem of Scope in my Attached Form. I define an Observable in my class constructor:

this.logOnObservable = new Ext.util.Observable();
this.logOnObservable.addEvents('LogOnExt_OnLogOn');
this.logOnObservable.on('LogOnExt_OnLogOn', Function.createDelegate(this, this.onLogOn));

logOnObservable is a public member of my class. This observable, when fired, would have to treated by the OnLogon handler defined im my class. The fireEvent is executed in the Hanlder of my LogInButton.

The problem is that, when executed the logOnObservable member is undefined. I suppose that the "this" in the button handler is in the scope of my Form and not in the scope of my Class.

How could I do it. How can I reference a member variable of my class from inside an Ext Js Form Button handler event.

Thanks in advance.

Condor
9 Oct 2010, 7:15 AM
1. on() (or addListener) supports specifying the scope in the third parameter, so you don't need to use createDelegate.
2. To be able to access this.logOnObservable the scope for the button needs to be changed:

buttons: [{
text: 'Login',
handler: function () {
var fields = Ext.getCmp('loginForm').getForm().getValues();
this.logOnObservable.fireEvent('LogOnExt_OnLogOn', fields);
},
scope: this
}

mvbaffa
9 Oct 2010, 7:57 AM
1. on() (or addListener) supports specifying the scope in the third parameter, so you don't need to use createDelegate.
2. To be able to access this.logOnObservable the scope for the button needs to be changed:

buttons: [{
text: 'Login',
handler: function () {
var fields = Ext.getCmp('loginForm').getForm().getValues();
this.logOnObservable.fireEvent('LogOnExt_OnLogOn', fields);
},
scope: this
}

Thank you very much. I worked !!!