Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS change position of default buttons in MessageBox (ExtJS 4.2.1)

If you use the code with the default buttons:

Ext.Msg.show({
 title:'Save Changes?',
 msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
 buttons: Ext.Msg.YESNOCANCEL,
 icon: Ext.Msg.QUESTION
});

the buttons on the window are in the order yes - no - cancel. I would like them in the order cancel - no - yes for consistency in my app. Is there a way to add a different configuration or change this for my needs?

like image 897
tgreen Avatar asked Feb 05 '23 20:02

tgreen


1 Answers

Default buttons is simply created within Ext.window.MessageBox.makeButton() private method based on Ext.window.MessageBox.buttonIds config and show / hide based on bitmask buttons: Ext.Msg.YESNOCANCEL.

So we just have to override buttonIds config and bitmasks:

    Ext.define('Ext.overrides.MessageBox', {
        override: 'Ext.window.MessageBox',

        OK: 1,           //0001
        CANCEL: 2,       //0010
        NO: 4,           //0100
        YES: 8,          //1000

        OKCANCEL: 3,     //0011
        YESNO: 12,       //1100
        YESNOCANCEL: 14, //1110

        buttonIds: [
            'ok', 'cancel', 'no', 'yes'
        ]
    });

Ext.Msg / Ext.MessageBox is singletones and initially defined as instance of Ext.window.MessageBox before our override (check last lines of Ext.MessageBox code).

So we have to override Ext.Msg / Ext.MessageBox aswell:

    Ext.Msg = Ext.MessageBox = new Ext.window.MessageBox();

Check this simple fiddle.

like image 87
Sergey Novikov Avatar answered Feb 07 '23 13:02

Sergey Novikov