PDA

View Full Version : when I toggle or fire the click event of a button the button isn't selected



flamant
28 Nov 2011, 5:41 AM
Hi,
I have a set of button that are grouped within a toggleGroup. In the click handler of the button, depending of a particular case I want to select (or toggle or fire the click event) the previous selected button.

I tried to
1) change the pressed property
2) toggle the previous button
3) fire the click event of the previous selected button

But it has no effect. The selected button is still the one that I have clicked



var newButton = new Ext.Button({
id: 'buttonId(i),
text: text(i),
enableToggle : true,
toggleGroup: 'role',
listeners: {
click: function(button, evt) {
if (condition1) {
Ext.MessageBox.confirm('title',
'boxMessage', function(btn) {
if (btn == 'yes') {
action1(param1, param2);
button.pressed = false;
button.toggle( false, true);
if (lastRoleButtonPressed != null) {
lastRoleButtonPressed.pressed = true;
lastRoleButtonPressed.toggle( true, true);
lastRoleButtonPressed.fireEvent('click', lastRoleButtonPressed);

}
} else if (btn == 'no') {
action2(param3, param4);

}
}
);

} else {
action2(param3, param4);
}


}
}
});
statusBar.insert(index, newButton);
}

}


How can I select the previous button ? What's wrong ?

Thank you in advance for your answers

tobiu
28 Nov 2011, 9:40 AM
button.pressed is a readOnly property.

the method:


toggle( [Boolean state], [Boolean supressEvent] ) : Ext.Button
If a state it passed, it becomes the pressed state otherwise the current state is toggled.

Parameters
state : Boolean (optional)
Force a particular state
supressEvent : Boolean (optional)
True to stop events being fired when calling this method.
Returns
Ext.Button
this


is the right way to go.

Are "condition1" and "lastRoleButtonPressed" global variables?! really not a nice coding style and this has potential for errors. check if lastRoleButtonPressed is not null, include logs and see what is happening.

flamant
28 Nov 2011, 12:27 PM
Hi tobiu and thank you for your answer

effectively "lastRoleButtonPressed" is a global variable that is the last button that was pressed among my set of button and I didn't find another way to store it

"condition1" is not a global variable: I simplified (replaced by "condition1") the code

I found a solution.

the following doesn't work


button.toggle( false, true);
lastRoleButtonPressed.toggle( true, true);


I tested it with logs and with firebug : no bugs, everything is normal but it doesn't work

On the other hand the following code works


button.toggle( true, true);
button.toggle( false, true);
lastRoleButtonPressed.toggle( false, true);
lastRoleButtonPressed.toggle( true, true);


I don't see why but this works. As if a first call well reinitialize the buttons

Thank you again