View Full Version : Are you sure you want to untoggle that SegmentedButton?

12 May 2012, 9:29 AM
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

requires: [

// rest of it

Override (to allow beforetoggle event):

Ext.define('App.view.override.SegmentedButton', {
override: 'Ext.SegmentedButton',

initialize: function () {
var me = this;

delegate: '> button',
scope: me,
tap: 'onButtonPress'


onButtonPress: function (button) {

var me = this,
pressedButtons = me.getPressedButtons() || [],
buttons = [],

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

onSegmentedbuttonBeforeToggle: function(segmentedbutton, button, wasPressed, options) {
// Remove ability to depress it so it doesnt change until confirmed

// 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') {



14 May 2012, 6:25 AM
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.