ExtJs Message box with Custom buttons

MNR picture MNR · Jun 7, 2011 · Viewed 31.5k times · Source

How to display ExtJS Message box with Custom buttons.

I want a Message box with a Custom message and "Cancel" and "Deactivate" Buttons. Please give some idea.

buttons: [{
    text: "Cancel",
    handler: function () {
        Ext.MessageBox.hide();
        //submitTicketForm();
    }
},{
    text: "Deactivate",
    handler: function () {
        Ext.MessageBox.hide();
    }
}],

I am using it like this but not getting any buttons.

Answer

Tower picture Tower · Nov 27, 2011

In ExtJS 4, you can make your own component like this:

Ext.define('App.view.MyDialog', {
    /**
     * Shows the dialog.
     */
    show: function() {
        var dialog = Ext.create('Ext.window.MessageBox', {
            buttons: [{
                text: 'baz',
                iconCls: 'icon-add',
                handler: function() {
                    dialog.close();
                }
            }]
        });

        dialog.show({
            title: 'foo!',
            msg: '<p>bar?</p>',
            icon: Ext.MessageBox.WARNING
        });

        dialog.setHeight(160);
        dialog.setWidth(420);
    }
});

then:

var dialog = Ext.create('App.view.MyDialog');
dialog.show();