namespace sap.ui.commons.MessageBox

Control sample: sap.ui.commons.MessageBox
Visiblity: public
Available since: N/A
Module: sap/ui/commons/MessageBox
Application Component: CA-UI5-CTR

Provides methods to create standard alerts, confirmation dialogs, or arbitrary message boxes.

As MessageBox is a static class, a jQuery.sap.require("sap.ui.commons.MessageBox"); statement must be explicitly executed before the class can be used. Example:

  jQuery.sap.require("sap.ui.commons.MessageBox");
  sap.ui.commons.MessageBox.show(
      "This message should appear in the message box.",
      sap.ui.commons.MessageBox.Icon.INFORMATION,
      "My message box title",
      [sap.ui.commons.MessageBox.Action.YES, sap.ui.commons.MessageBox.Action.NO],
      function() { / * do something * / }
  );


Nodes Overview

Node Description
sap.ui.commons.MessageBox.Action

Enumeration of supported actions in a MessageBox.

sap.ui.commons.MessageBox.Icon

Enumeration of the pre-defined icons that can be used in a MessageBox.


Methods Overview

Method Description
sap.ui.commons.MessageBox.alert

Displays an alert box with the given message and an OK button (no icons). If a callback is given, it is called after the alert box has been closed by the user via the OK button or via the Close icon. The callback is called with the following signature:

  function ()

The alert box opened by this method is modal and it is processed asynchronously. Applications have to use the fnCallback to continue work after the user closed the alert box.

sap.ui.commons.MessageBox.confirm

Displays a confirmation dialog box with the given message, a question icon, an OK button, and a Cancel button. If a callback is given, it is called after the alert box has been closed by the user via one of the buttons or via the close icon. The callback is called with the following signature

  function(bConfirmed)

where bConfirmed is set to true when the user has activated the OK button.

The confirmation dialog box opened by this method is modal and it is processed asynchronously. Applications have to use the fnCallback to continue work after the user closed the alert box.

sap.ui.commons.MessageBox.show

Creates and displays a simple message box with the given text and buttons, and optionally other parts. After the user has selected a button or closed the message box using the close icon, the callback function is invoked when given.

The only mandatory parameter is vMessage. Either a string with the corresponding text or even a layout control could be provided.

The created dialog box is executed asynchronously. When it has been created and registered for rendering, this function returns without waiting for a user reaction.

When applications have to react on the users choice, they have to provide a callback function and postpone any reaction on the user choice until that callback is triggered.

The signature of the callback is

function (oAction);

where oAction is the button that the user has pressed. When the user has pressed the close button, a MessageBox.Action.Close is returned.

sap.ui.commons.MessageBox.alert

Displays an alert box with the given message and an OK button (no icons). If a callback is given, it is called after the alert box has been closed by the user via the OK button or via the Close icon. The callback is called with the following signature:

  function ()

The alert box opened by this method is modal and it is processed asynchronously. Applications have to use the fnCallback to continue work after the user closed the alert box.

Param Type DefaultValue Description
vMessage string sap.ui.core.Control

Message to be displayed in the alert box

fnCallback function

callback function to be called when the user closed the dialog

sTitle string

Title to be displayed in the alert box

sDialogId string

ID to be used for the alert box. Intended for test scenarios, not recommended for productive apps

sap.ui.commons.MessageBox.confirm

Displays a confirmation dialog box with the given message, a question icon, an OK button, and a Cancel button. If a callback is given, it is called after the alert box has been closed by the user via one of the buttons or via the close icon. The callback is called with the following signature

  function(bConfirmed)

where bConfirmed is set to true when the user has activated the OK button.

The confirmation dialog box opened by this method is modal and it is processed asynchronously. Applications have to use the fnCallback to continue work after the user closed the alert box.

Param Type DefaultValue Description
vMessage string sap.ui.core.Control

Message to display

fnCallback function

Callback to be called

sTitle string

Title to display

sDialogId string

ID to be used for the confirmation dialog. Intended for test scenarios, not recommended for productive apps

sap.ui.commons.MessageBox.show

Creates and displays a simple message box with the given text and buttons, and optionally other parts. After the user has selected a button or closed the message box using the close icon, the callback function is invoked when given.

The only mandatory parameter is vMessage. Either a string with the corresponding text or even a layout control could be provided.

The created dialog box is executed asynchronously. When it has been created and registered for rendering, this function returns without waiting for a user reaction.

When applications have to react on the users choice, they have to provide a callback function and postpone any reaction on the user choice until that callback is triggered.

The signature of the callback is

function (oAction);

where oAction is the button that the user has pressed. When the user has pressed the close button, a MessageBox.Action.Close is returned.

Param Type DefaultValue Description
vMessage string sap.ui.core.Control

The message to be displayed.

oIcon sap.ui.commons.MessageBox.Icon None

The icon to be displayed.

sTitle string ''

The title of the message box.

vActions sap.ui.commons.MessageBox.Action sap.ui.commons.MessageBox.Action[]

Either a single action, or an array of actions. If no action(s) are given, the single action MessageBox.Action.OK is taken as a default for the parameter.

fnCallback function

Function to be called when the user has pressed a button or has closed the message box.

oDefaultAction sap.ui.commons.MessageBox.Action

Must be one of the actions provided in vActions.

sDialogId string

ID to be used for the dialog. Intended for test scenarios, not recommended for productive apps