Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs Message box with Custom buttons

Tags:

extjs

extjs3

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.

like image 621
MNR Avatar asked Jun 07 '11 05:06

MNR


3 Answers

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();
like image 185
Tower Avatar answered Nov 09 '22 02:11

Tower


MessageBox is an single instance of an internally managed Window used for prompt, show, alert, etc.

You can change the buttonText by passing in a string for show like this:

buttons: {ok: "Foo", cancel: "Bar"}

Refer : MessageBox

buttons: { 
                ok: "Foo", 
                handler: function(){ 
                    Ext.MessageBox.hide(); 

                },
                cancel: "Bar",
                handler: function(){
                    Ext.MessageBox.hide();
                }
        }
like image 37
MMT Avatar answered Nov 09 '22 00:11

MMT


Use 'buttonText' instead of 'button',

buttonText: {ok: 'Deactivate', cancel: 'Cancel'},
fn: function(btn) {
    if (btn === 'ok') {
        Ext.MessageBox.hide();
    }  else {
        Ext.MessageBox.hide(); 
    } 
}
like image 42
Jeff Johny Avatar answered Nov 09 '22 00:11

Jeff Johny