PDA

View Full Version : l.fireFn is undefined when calling event on window



aacoro
23 May 2011, 1:44 PM
Hi all,
I think that I'm missing a big point in event handler but I'm stuck /:)

I have a menu item that will open a new window with OK button and CANCEL button.
This is my window:



var dialog = new Ext.Window({
title : 'Skills',
height : 350,
width : 400,
scope : this,
modal : true,
closable : false,
items : formPanel,
buttons : [
{ text:'Ok', handler:function(){ dialog.fireEvent('saveMapping'), dialog.hide() } },
{ text:'Annuleren', handler:function(){ dialog.hide() } }
]
});


When I click cancel it close my window. But when I click OK it should fire my event but it does not. Instead it gives the error:



l.fireFn is undefined on line 310 of ext-all-debug.js...


This is my saveMapping event:


// String eventName, Function handler, [Object scope], [Object options]
skillsDialog.addListener('saveMapping', this.saveData, this);

saveData : function(){

myStore.filterBy(function(record) {
if(record.get('Visible') == true){
console.log('true');
} else {
console.log('false');
}
});

};


What am I doing wrong overhere??
Thanks!

skirtle
23 May 2011, 7:00 PM
I believe the problem is that this.saveData is undefined when you call addListener(). Your final code snippet appears to be incomplete so it's a little hard to be sure what the exact problem is but I'd guess that this isn't scoped to the object you think it is.

aacoro
23 May 2011, 11:49 PM
I believe the problem is that this.saveData is undefined when you call addListener(). Your final code snippet appears to be incomplete so it's a little hard to be sure what the exact problem is but I'd guess that this isn't scoped to the object you think it is.

Thanks for your reply I was thinking that my problem was that I do not fully understand the scoping part.. but I cannot fix it :-(

This is my entire code:



Skills = function() {

var formPanel = {
xtype : 'form',
title : 'Your Skills',
labelWidth: 110,
items : checkboxes,
frame : true
};

var dialog = new Ext.Window({
title : 'Skills',
height : 350,
width : 400,
modal : true,
closable : false,
items : formPanel,
buttons : [
{ text:'Ok', handler:function(){ dialog.fireEvent('saveMapping'), dialog.hide() } },
{ text:'Annuleren', handler:function(){ dialog.hide() } }
]
});
// String eventName, Function handler, [Object scope], [Object options]
dialog.addListener('saveMapping', this.saveData, this);

saveData : function(){
resourcePlanon.filterBy(function(record) {
if(record.get('Visible') == true){
console.log('true');
} else {
console.log('false');
}
});
};

return dialog;

};


and I calling with from another window (menu item) as said in my previous post:



var skillsDialog = new Skills();
skillsDialog.show();

friend
24 May 2011, 3:59 AM
Try this:



Skills = function() {
var formPanel = {
xtype : 'form',
title : 'Your Skills',
labelWidth: 110,
items : checkboxes,
frame : true
};

var dialog = new Ext.Window({
title : 'Skills',
height : 350,
width : 400,
modal : true,
closable : false,
items : formPanel,
buttons : [
{ text:'Ok', handler:function(){ saveData(); dialog.hide(); } },
{ text:'Annuleren', handler:function(){ dialog.hide() } }
]
});

function saveData()
{
resourcePlanon.filterBy(function(record) {
if(record.get('Visible') == true) {
console.log('true');
} else {
console.log('false');
}
});
}

return dialog;
};

aacoro
25 May 2011, 7:11 AM
Try this:



Skills = function() {
var formPanel = {
xtype : 'form',
title : 'Your Skills',
labelWidth: 110,
items : checkboxes,
frame : true
};

var dialog = new Ext.Window({
title : 'Skills',
height : 350,
width : 400,
modal : true,
closable : false,
items : formPanel,
buttons : [
{ text:'Ok', handler:function(){ saveData(); dialog.hide(); } },
{ text:'Annuleren', handler:function(){ dialog.hide() } }
]
});

function saveData()
{
resourcePlanon.filterBy(function(record) {
if(record.get('Visible') == true) {
console.log('true');
} else {
console.log('false');
}
});
}

return dialog;
};


Thanks friend,
this one works fine :-)

This is the correct way to add such a listener or would you advise to do change the design of this??