PDA

View Full Version : Event is still fired after invoking the suspendEvents method



thachun
10 Aug 2012, 12:36 AM
Hi all,

As I understand, if we want to stop firing event on a component, we just call the suspendEvent method and resume the suspended events by the resumeEvents method. Correct me if I am wrong.
However, in my case, I created a simple code to check if it works as I expected by listening the click event on a button. Then, in the handler, I suspended events on that button but it's so unusual that the next clicks it still jump into the handler :-(.

Please help me and thx a lots!

Cheers,
Thach

vietits
10 Aug 2012, 1:26 AM
suspendEvents() and resumeEvents() work as expected for me on Chrome 20 & Ext 4.1.1. Try this:


Ext.onReady(function(){
var button = Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Click Me!',
listeners: {
click: function(){
console.log('Button is clicked')
}
}
});


Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Suspend events',
listeners: {
click: function(){
button.suspendEvents();
console.log('Suspend Events on Button')
}
}
});


Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Resume events',
listeners: {
click: function(){
button.resumeEvents();
console.log('Resume Events on Button')
}
}
});
});

harman
10 Aug 2012, 7:39 AM
Its a minor mistake that you are missing the required params in function for click events
It takes three params as below.
Try this its working fine



Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Suspend events',
listeners: {
click: function(button,event,eOpts){
button.suspendEvents();
console.log('Suspend Events on Button')
}
}
});



Regards,
Harman

vietits
10 Aug 2012, 4:44 PM
@harman,

It is not a mistake. In my example, I used 2nd and 3rd buttons to suspend and to resume events on the first button, not on the button that fires events. Look at my example again, button is a variable that represents the first button, not from argument list of event handler as you mentioned.

thachun
12 Aug 2012, 10:34 PM
Thanks for your code. It works for me but not when I put the listener into a controller :-(.


suspendEvents() and resumeEvents() work as expected for me on Chrome 20 & Ext 4.1.1. Try this:


Ext.onReady(function(){
var button = Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Click Me!',
listeners: {
click: function(){
console.log('Button is clicked')
}
}
});


Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Suspend events',
listeners: {
click: function(){
button.suspendEvents();
console.log('Suspend Events on Button')
}
}
});


Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Resume events',
listeners: {
click: function(){
button.resumeEvents();
console.log('Resume Events on Button')
}
}
});
});

thachun
12 Aug 2012, 10:41 PM
It is a bug raised here :-(
http://www.sencha.com/forum/showthread.php?171525-suspendEvents-did-not-affect-to-Ext.app.Controller.control

harman
13 Aug 2012, 12:42 AM
Sorry Vietits, I interpreted it the wrong way.
If thats your intention, its working right.
your example works on Firefox 3.6 for me as well.
And politely, If you use listener rather than handler i think you should atleast define the params.
or else put them straight into the handler.
Also, i dont know why arent these params given as optional in the Docs. :s