Venkat Papana
Venkat Papana

Reputation: 4927

ExtJS 4.1: MessageBox 4 buttons

I'm trying to have 4 buttons for a closable MessageBox and realized that the close(x) button is invoking my 4th button's custom function instead of closing the dialog.

here is my button config:

{
  ok      : 'Action1',
  yes     : 'Action2',
  no      : 'Action3', 
  cancel  : 'Action4'
}

handler code:

fn : function(buttonId, text, option) {
switch (buttonId)
    {
        case 'ok' :
            action1();
            break ;
        case 'yes' :
            action2();
            break ;
        case 'no' :
            action3();
            break ;
        case 'cancel' :
            action4();
            break ;                                         
    }
}

Any help?

Upvotes: 0

Views: 342

Answers (1)

Nail Shakirov
Nail Shakirov

Reputation: 654

Here's the way for solve your problem. I created new window with 4 buttons as default YESNOCANCEL window.

enter image description here

Here's code of window:

Ext.define('MyApp.view.MyWindow', {
extend: 'Ext.window.Window',

requires: [
    'Ext.container.Container',
    'Ext.Img',
    'Ext.form.Label',
    'Ext.button.Button'
],

autoShow: true,
border: false,
height: 165,
width: 329,
title: 'Save Changes?',

layout: {
    type: 'vbox',
    align: 'stretch'
},

initComponent: function() {
    var me = this;

    Ext.applyIf(me, {
        items: [
            {
                xtype: 'container',
                flex: 3,
                margin: 5,
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                },
                items: [
                    {
                        xtype: 'image',
                        flex: 1,
                        height: 86,
                        padding: 15,
                        width: 113,
                        src: 'icon-question.png'
                    },
                    {
                        xtype: 'label',
                        flex: 3,
                        padding: '15 10 5 10',
                        text: 'You are closing a tab that has unsaved changes. Would you like to save your changes?'
                    }
                ]
            },
            {
                xtype: 'container',
                flex: 2,
                padding: '10 5 10 5',
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                },
                items: [
                    {
                        xtype: 'button',
                        flex: 1,
                        margin: '0 5 0 0',
                        text: 'Yes'
                    },
                    {
                        xtype: 'button',
                        flex: 1,
                        margin: '0 5 0 0',
                        text: 'No'
                    },
                    {
                        xtype: 'button',
                        flex: 1,
                        margin: '0 5 0 0',
                        text: 'New Button'
                    },
                    {
                        xtype: 'button',
                        flex: 1,
                        text: 'Cancel'
                    }
                ]
            }
        ]
    });

    me.callParent(arguments);
}

});

Upvotes: 1

Related Questions