Results 1 to 2 of 2

Thread: Are you sure you want to untoggle that SegmentedButton?

  1. #1
    Sencha Premium Member intellix's Avatar
    Join Date
    Mar 2012
    Location
    UK + Malta
    Posts
    263
    Vote Rating
    18
      0  

    Default Are you sure you want to untoggle that SegmentedButton?

    Ok so the project I'm working on required a confirmation dialog to ask the user if they were sure they wanted to untoggle a SegmentedButton. This is the first time for me using ExtJS, ST2 so you may not appreciate what I've created... but here it is:

    Inside Ext.application you need to specify that you want to use an over-ride which exists as app/view/override/SegmentedButton.js
    Code:
    Ext.application({
        requires: [
            'App.view.override.SegmentedButton'
        ],
    
        // rest of it
    Override (to allow beforetoggle event):
    Code:
    Ext.define('App.view.override.SegmentedButton', {
        override: 'Ext.SegmentedButton',
    
    
        initialize: function () {
            var me = this;
    
    
            me.on({
                delegate: '> button',
                scope: me,
                tap: 'onButtonPress'
            });
    
    
            me.callParent();
        },
    
    
        onButtonPress: function (button) {
    
    
            var me = this,
                pressedButtons = me.getPressedButtons() || [],
                buttons = [],
                alreadyPressed;
    
    
            wasPressed = (buttons.indexOf(button) !== -1) || (pressedButtons.indexOf(button) !== -1);
    
    
            me.fireEvent('beforetoggle', me, button, wasPressed);
    
    
        }
        
    });
    beforetoggle event within my controller which is called on 'beforetoggle':
    Code:
    onSegmentedbuttonBeforeToggle: function(segmentedbutton, button, wasPressed, options) {
            // Remove ability to depress it so it doesnt change until confirmed
            segmentedbutton.setAllowDepress(false);
    
    
            // Check if button is already down
            if (wasPressed) {
    
    
                // Is user sure he wants to remove that selection?
                Ext.Msg.confirm("Confirmation", "Are you sure you want to remove that selection?", function (reply) {
    
    
                    if (reply === 'yes') {
                        segmentedbutton.setAllowDepress(true);
                        segmentedbutton.onButtonRelease(button);
                    }
    
    
                });
    
    
            }
        },

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,416
    Vote Rating
    1270
      0  

    Default

    I would think this would be better suited for a plugin or an extension of segmentedbutton. If you use an override, you override all segmentedbuttons which you may not want.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread

Posting Permissions

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