PDA

View Full Version : Button Toggle Group click event being fired when allowDepress:false



scancubus
18 Dec 2011, 2:58 PM
Hello,
I am glad that you added a config for "allowDepress" with a button toggle group. However, if you set it to false, I don't think that the buttons "click" event should be fired. If it is a valid toggle, it makes sense to fire, otherwise, do not fire the event. Thoughts?


{
xtype : 'button',
allowDepress:false,
text : 'Range',
enableToggle:true,
toggleGroup : 'myToggleGroup',
pressed : true,
listeners:{
click:function(){
Ext.log('button click event fired on Range');
},
scope:this
}
}, {
xtype : 'button',
allowDepress:false,
text : 'Specific',
enableToggle:true,
toggleGroup : 'myToggleGroup',
listeners:{
click:function(){
Ext.log('button click event fired on Specific');
},
scope:this
}
}


Please notice that the log shows the click event has been fired when the button is already pressed.
Thanks.

evant
18 Dec 2011, 10:28 PM
That behaviour is expected. Regardless of the pressed state, you're still clicking the button. If you only want to listen for when the button is toggled, use the toggleHandler:



Ext.onReady(function() {

var makeButton = function(num, pressed){
Ext.create('Ext.button.Button', {
renderTo: document.body,
text: 'B' + num,
pressed: pressed,
toggleGroup: 'group',
allowDepress: false,
handler: function(btn){
console.log('handler', btn.text);
},
toggleHandler: function(btn, pressed){
console.log('toggle', btn.text, pressed);
}
});
};

for (var i = 1; i <= 5; ++i) {
makeButton(i, i === 3);
}

});