Documentation

MessageBox class

Description and options

Class for creating standard informational dialog windows (alert and confirm).

new BX.UI.Dialogs.MessageBox(
{
    options;
}
);

Class object options

options {object} — set if dialog window options. List of dialog options in a table:

Dialog optionTypeDescription
messagestring|Element|NodeDialog window message. HTML string or DOM element.
titlestringDialog window title.
modalbooleanWhen true, dialog window opens with overlay.
cacheablebooleanBy default, after closing, dialog window is erased from DOM. It can be cancelled: specify cacheable: false.
minWidthnumberMinimal window width.
minHeightnumber Minimal window height.
maxWidthnumberMaximum window width.
onOkFunctionOK button handler function.
onCancelFunctionCancel button handler function.
onYesFunctionYes button handler function.
onNoFunctionNo button handler function.
okCaptionstringOK button caption.
cancelCaptionstringCancel button caption.
yesCaptionstringYes button caption.
noCaptionstringNo button caption.
mediumButtonSizebooleanDefault dialog window buttons have small dimensions. When parameter mediumButtonSize set as true, button size becomes standard (medium). When parameter title is set, property mediumButtonSize automatically is set as true (cancel this behaviour via mediumButtonSize: false).
buttonsMessageBoxButtons | ArrayDefines set of dialog window buttons. Structure MessageBoxButtons defines the following standard sets:
  • MessageBoxButtons.OK — OK button.
  • MessageBoxButtons.CANCEL — Cancel button.
  • MessageBoxButtons.YES — Yes button.
  • MessageBoxButtons.NO — No button.
  • MessageBoxButtons.OK_CANCEL — OK and Cancel buttons.
  • MessageBoxButtons.YES_NO — Yes and No buttons.
  • MessageBoxButtons.YES_CANCEL — Yes and Cancel buttons.
  • MessageBoxButtons.YES_NO_CANCEL — Yes, No and Cancel buttons.
To create your own set of buttons, specify the buttons array BX.UI.Button.
popupOptionsobjectSet of options for BX.PopupWindow.

Example


Methods

MethodDescription
messageBox.showShows dialog window on a page.
messageBox.closeCloses dialog window on a page.
messageBox.getPopupWindowReturns object BX.PopupWindow.
messageBox.setMessageSets dialog window content. HTML string or DOM element.
messageBox.getMessageReturn dialog window content.
messageBox.setTitleSets dialog window title.
messageBox.getTitleReturns dialog window title.
messageBox.getOkButtonReturns OK button (class object BX.UI.Button).
messageBox.getCancelButtonReturns Cancel button (class object BX.UI.Button).
messageBox.getYesButtonReturns Yes button (class object BX.UI.Button).
messageBox.getNoButtonReturns No button (class object BX.UI.Button).
messageBox.setButtonsDefines dialog window set of buttons. Set is specified by the structure MessageBoxButtons or by array of objects BX.UI.Button.
  • MessageBoxButtons.OK — OK button.
  • MessageBoxButtons.CANCEL — Cancel button.
  • MessageBoxButtons.YES — Yes button.
  • MessageBoxButtons.NO — No button.
  • MessageBoxButtons.OK_CANCEL — OK and Cancel buttons.
  • MessageBoxButtons.YES_NO — OK and No buttons.
  • MessageBoxButtons.YES_CANCEL — Yes and Cancel buttons.
  • MessageBoxButtons.YES_NO_CANCEL — Yes, No and Cancel buttons.
messageBox.getButtonsReturns array of dialog buttons.
messageBox.setOkCaptionSets OK button caption.
messageBox.setCancelCaptionSets Cancel button caption.
messageBox.setYesCaptionSets Yes button caption.
messageBox.setNoCaptionSets No button caption.
messageBox.setOkCallbackSets OK button caption.
messageBox.setCancelCallbackSets Cancel button caption.
messageBox.setYesCallbackSets Yes handler.
messageBox.setNoCallbackSets No button handler.
MessageBox.createDialog window static method.

options {object} — set of dialog window options (see option description in new MessageBox).

MessageBox.showCreates and shows dialog window on a page.

options {object} — set of dialog window options (see option description in new MessageBox).

MessageBox.alertStatic method for creating informational dialog windows (alert).
alert(message: string | Element | Node, okCallback?: Function, okCaption?: string);
alert(message: string | Element | Node, title?: string, okCallback?: Function, okCaption?: string);
MessageBox.confirmStatic method for creating confirmation dialog windows.
confirm(message: string | Element | Node, okCallback?: Function, okCaption?: string, cancelCallback?: Function);
confirm(message: string | Element | Node, title: string, okCallback?: Function, okCaption?: string, cancelCallback?: Function);

Examples

Creating class object

const messageBox = new BX.UI.Dialogs.MessageBox(
{
    message: "Are you sure you want delete this file?",
    title: "Confirm deleting",
    buttons: BX.UI.Dialogs.MessageBoxButtons.OK_CANCEL,
    okCaption: "Yes",
    onOk: function() 
    {
        console.log("onOk");
    },
}
);


messageBox.show();

Arbitrary button titles and callbacks

const messageBox = new BX.UI.Dialogs.MessageBox(
{
    message: "Various button titles",
    title: "Confirm deleting",
    buttons: BX.UI.Dialogs.MessageBoxButtons.YES_NO_CANCEL,
    yesCaption: "Yes caption",
    noCaption: "No caption",
    cancelCaption: "Cancel caption",
    maxWidth: 600,
    onYes: function() 
    {
        console.log("onYes");
        messageBox.close();
    },
    onNo: function() 
    {
        console.log("onNo");
        messageBox.close();
    },
    onCancel: function(messageBox) 
    {
        console.log("onCancel");
        messageBox.close();
    },
}
);

messageBox.show();

Options for BX.PopupWindow

BX.UI.Dialogs.MessageBox.show({
    message: "Text with description of this popup, located here.",
    buttons: BX.UI.Dialogs.MessageBoxButtons.OK_CANCEL,
    popupOptions: {
        bindElement: BX("yesnocancel"),
        offsetLeft: 20,
        closeIcon: true,
        events: {
            onPopupClose: function() {
                BX.UI.Dialogs.MessageBox.alert("Popup closed.");
            }
        }
    }
});

© «Bitrix24», 2001-2024