ExtJs Message box with Custom buttons

瘦欲@ 提交于 2019-12-03 05:52:34

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();
                }
        }

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();

Use 'buttonText' instead of 'button',

buttonText: {ok: 'Deactivate', cancel: 'Cancel'},
fn: function(btn) {
    if (btn === 'ok') {
        Ext.MessageBox.hide();
    }  else {
        Ext.MessageBox.hide(); 
    } 
}

In ExtJS 4 and ExtJS 5, to set custom text for buttons you need to use both buttons and buttonText configs:

buttons: [{
    Ext.Msg.OK
}],
buttonText: { 
    ok: "Custom text"
},
fn: function() { 
    // ...handle OK button
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!