Search code examples
javascriptextjssencha-touch-2

How to get the button pressed on a segmentedButton in Sencha


I am newbie in Sencha Touch and I have a "segmentedButton" component, and I need to get the button pressed depending the user interaction in the controller.

Help please!!


Solution

  • You can use the getPressedButtons() method.

    Example:

    Ext.application({
        name : 'Fiddle',
    
        launch : function() {
            var segmentedButton = Ext.create('Ext.SegmentedButton', {
                allowMultiple: true,
                items: [{
                    text: 'Option 1'
                },{
                    text: 'Option 2',
                    pressed: true
                },{
                    text: 'Option 3'
                }],
                listeners: {
                    toggle: function(container, button, pressed){
                        alert("User toggled the '" + button.getText() + "' button: " + (pressed ? 'on' : 'off'));
                        console.log(container.getPressedButtons());
                    }
                }
            });
            Ext.Viewport.add({ xtype: 'container', padding: 10, items: [segmentedButton] });
        }
    });