PDA

View Full Version : How to use removeListener?



dotnetCarpenter
9 May 2007, 4:03 PM
Can someone explain to me how the removeListener works?
I have two buttons that works as previous and next navigation in a wizard made of tabs and at the last tab the next button changes to a save function. I want to remove that function when the user opens the wizard again but I don't understand what Function handler is.
My code look something like this:

var btnNext = dialog.addButton(la_next, function(){
this.CurrentStep++;
tabs.getNextAvailable(this.CurrentStep).activate();
btnBack.enable();
if(this.CurrentStep == tabs.getCount())
{
btnNext.setText(la_save);
// add a new handler to save the gartered input
btnNext.on('click', function(){
dialog.hide();
}, dialog);
}
}, this);
dialog.addButton(la_close, dialog.hide, dialog);
dialog.on('beforeshow', function(){
btnBack.disable();
if(btnNext.getText!=la_next)
btnNext.setText(la_next);
// remove the save function (if it's there)
btnNext.un('click', dialog.hide(), dialog); // what should I put as the second argument?
});
Do I need to put a named function in my click eventhandler and then remove it by giving the un function a that name?

Thanks in advance!

dotnetCarpenter
9 May 2007, 4:13 PM
I should check my question before I ask next time... It works with a named function. Is this the correct way of doing it?

tryanDLS
9 May 2007, 4:13 PM
Do I need to put a named function in my click eventhandler and then remove it by giving the un function a that name?

Thanks in advance!
Yes you do - you can see examples of this in the source code.