Results 1 to 3 of 3

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

  1. #1
    Sencha User
    Join Date
    Jul 2010
    Posts
    304

    Default when I toggle or fire the click event of a button the button isn't selected

    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

    Code:
                            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

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default

    button.pressed is a readOnly property.

    the method:
    Code:
    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.
    Best regards
    Tobias Uhlig

  3. #3
    Sencha User
    Join Date
    Jul 2010
    Posts
    304

    Default

    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
    Code:
    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
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •