Namespace sap.ui.commons.MessageBoxModule: sap/ui/commons/MessageBox


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 * / }
  );

Deprecated API:Since version 1.38. Instead, use the sap.m.MessageBox control.


Since: 0.8.8.
Namespaces & Classes
ActionEnumeration of supported actions in a MessageBox.
IconEnumeration of the pre-defined icons that can be used in a MessageBox.
Method Summary
sap.ui.commons.MessageBox.alert(vMessage, fnCallback?, sTitle?, sDialogId?)Displays an alert box with the given message and an OK button (no icons).
sap.ui.commons.MessageBox.confirm(vMessage, fnCallback?, sTitle?, sDialogId?)Displays a confirmation dialog box with the given message, a question icon, an OK button, and a Cancel button.
sap.ui.commons.MessageBox.show(vMessage, oIcon?, sTitle?, vActions?, fnCallback?, oDefaultAction?, sDialogId?)Creates and displays a simple message box with the given text and buttons, and optionally other parts.
Method Detail
sap.ui.commons.MessageBox.alert(vMessage, fnCallback?, sTitle?, sDialogId?)
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.

Parameters:
{string|sap.ui.core.Control}vMessage Message to be displayed in the alert box
{function}fnCallback? callback function to be called when the user closed the dialog
{string}sTitle? Title to be displayed in the alert box
{string}sDialogId? ID to be used for the alert box. Intended for test scenarios, not recommended for productive apps
sap.ui.commons.MessageBox.confirm(vMessage, fnCallback?, sTitle?, sDialogId?)
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.

Parameters:
{string|sap.ui.core.Control}vMessage Message to display
{function}fnCallback? Callback to be called
{string}sTitle? Title to display
{string}sDialogId? ID to be used for the confirmation dialog. Intended for test scenarios, not recommended for productive apps
sap.ui.commons.MessageBox.show(vMessage, oIcon?, sTitle?, vActions?, fnCallback?, oDefaultAction?, sDialogId?)
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.

Parameters:
{string|sap.ui.core.Control}vMessage The message to be displayed.
{sap.ui.commons.MessageBox.Icon}oIcon?, Default: None The icon to be displayed.
{string}sTitle?, Default: '' The title of the message box.
{sap.ui.commons.MessageBox.Action|sap.ui.commons.MessageBox.Action[]}vActions? 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.
{function}fnCallback? Function to be called when the user has pressed a button or has closed the message box.
{sap.ui.commons.MessageBox.Action}oDefaultAction? Must be one of the actions provided in vActions.
{string}sDialogId? ID to be used for the dialog. Intended for test scenarios, not recommended for productive apps