Namespace sap.m.MessageBoxModule: sap/m/MessageBox
Provides easier methods to create sap.m.Dialog with type sap.m.DialogType.Message, such as standard alerts, confirmation dialogs, or arbitrary message dialogs.
As MessageBox
is a static class, a jQuery.sap.require("sap.m.MessageBox");
statement must be explicitly executed before the class can be used. Example:
jQuery.sap.require("sap.m.MessageBox"); sap.m.MessageBox.show( "This message should appear in the message box.", { icon: sap.m.MessageBox.Icon.INFORMATION, title: "My message box title", actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO], onClose: function(oAction) { / * do something * / } } );
Since: 1.21.2.
sap.m.MessageBox.alert("This message should appear in the alert", { title: "Alert", // default onClose: null, // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
If a callback is given, it is called after the alert dialog has been closed by the user via the OK button. The callback is called with the following signature:
function (oAction)
where oAction
can be either sap.m.MessageBox.Action.OK when the alert dialog is closed by tapping on the OK button or null when the alert dialog is closed by calling sap.m.InstanceManager.closeAllDialogs()
.
The alert dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the alert dialog.
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | callback function to be called when the user closes the dialog |
{string} | mOptions.title?, Default: 'Alert' | Title to be displayed in the alert dialog |
{string} | mOptions.id? | ID to be used for the alert dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | Added since version 1.21.2. CSS style class which is added to the alert dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | Added since version 1.28.0. initialFocus, this option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Added since version 1.28. Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
sap.m.MessageBox.confirm("This message should appear in the confirmation", { title: "Confirm", // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The callback is called with the following signature
function(oAction)
where oAction is set by one of the following three values: 1. sap.m.MessageBox.Action.OK: OK (confirmed) button is tapped. 2. sap.m.MessageBox.Action.Cancel: Cancel (unconfirmed) button is tapped. 3. null: Confirm dialog is closed by calling sap.m.InstanceManager.closeAllDialogs()
The confirmation dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the confirmation dialog
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | Callback to be called when the user closes the dialog |
{string} | mOptions.title?, Default: 'Confirmation' | Title to display in the confirmation dialog |
{string} | mOptions.id? | ID to be used for the confirmation dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | Added since version 1.21.2. CSS style class which is added to the confirmation dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | Added since version 1.28.0. initialFocus, this option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Added since version 1.28. Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
sap.m.MessageBox.error("This message should appear in the error message box", { title: "Error", // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The callback is called with the following signature
function (oAction)
The error dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the error dialog.
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | Callback when the user closes the dialog |
{string} | mOptions.title?, Default: 'Error' | Title of the error dialog |
{string} | mOptions.id? | ID for the error dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | CSS style class which is added to the error dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | This option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
- Since:
- 1.30
sap.m.MessageBox.information("This message should appear in the information message box", { title: "Information", // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The callback is called with the following signature *
function (oAction)
The information dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the information dialog
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | Callback when the user closes the dialog |
{string} | mOptions.title?, Default: 'Information' | Title of the information dialog |
{string} | mOptions.id? | ID for the information dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | CSS style class which is added to the information dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | This option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
- Since:
- 1.30
onClose
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.
sap.m.MessageBox.show("This message should appear in the message box", { icon: sap.m.MessageBox.Icon.NONE, // default title: "", // default actions: sap.m.MessageBox.Action.OK // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The created dialog 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 tapped. For example, when the user has pressed the close button, a sap.m.MessageBox.Action.Close is returned.
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{sap.m.MessageBox.Icon} | mOptions.icon? | The icon to be displayed. |
{string} | mOptions.title? | The title of the message box. |
{sap.m.MessageBox.Action|sap.m.MessageBox.Action[]|string|string[]} | mOptions.actions?, Default: sap.m.MessageBox.Action.OK | Either a single action, or an array of two actions. If no action(s) are given, the single action MessageBox.Action.OK is taken as a default for the parameter. From UI5 version 1.21, more than 2 actions are supported. For the former versions, if more than two actions are given, only the first two actions are taken. Custom action string(s) can be provided, and then the translation of custom action string(s) needs to be done by the application. |
{function} | mOptions.onClose? | Function to be called when the user taps a button or closes the message box. |
{string} | mOptions.id? | ID to be used for the dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | Added since version 1.21.2. CSS style class which is added to the dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | Added since version 1.28.0. initialFocus, this option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Added since version 1.28. Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
{string} | mOptions.details? | Added since version 1.28.0. If 'details' is set in the MessageBox, a 'Show detail' link is added. When you click the link, it is set to visible = false and the text area containing 'details' information is then displayed. |
sap.m.MessageBox.success("This message should appear in the success message box", { title: "Success", // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The callback is called with the following signature
function(oAction)
The success dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the success dialog
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | Callback when the user closes the dialog |
{string} | mOptions.title?, Default: 'Success' | Title of the success dialog |
{string} | mOptions.id? | ID for the success dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | CSS style class which is added to the success dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | This option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
- Since:
- 1.30
sap.m.MessageBox.warning("This message should appear in the warning message box", { title: "Warning", // default onClose: null // default styleClass: "" // default initialFocus: null // default textDirection: sap.ui.core.TextDirection.Inherit // default });
The callback is called with the following signature *
function (oAction)
The warning dialog opened by this method is processed asynchronously. Applications have to use fnCallback
to continue work after the user closed the warning dialog
{string} | vMessage | Message to be displayed in the alert dialog. The usage of sap.core.Control as vMassage is deprecated since version 1.30.4. |
{object} | mOptions? | Other options (optional) |
{function} | mOptions.onClose? | Callback when the user closes the dialog |
{string} | mOptions.title?, Default: 'Warning' | Title of the warning dialog |
{string} | mOptions.id? | ID to for the warning dialog. Intended for test scenarios, not recommended for productive apps |
{string} | mOptions.styleClass? | CSS style class which is added to the warning dialog's root DOM node. The compact design can be activated by setting this to "sapUiSizeCompact" |
{string|sap.m.MessageBox.Action} | mOptions.initialFocus? | This option sets the action name, the text of the button or the control that gets the focus as first focusable element after the MessageBox is opened. The usage of sap.ui.core.Control to set initialFocus is deprecated since version 1.30.4. |
{sap.ui.core.TextDirection} | mOptions.textDirection? | Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM. |
{boolean} | deprecated mOptions.verticalScrolling? | verticalScrolling is deprecated since version 1.30.4. VerticalScrolling, this option indicates if the user can scroll vertically inside the MessageBox when the content is larger than the content area. |
{boolean} | deprecated mOptions.horizontalScrolling? | horizontalScrolling is deprecated since version 1.30.4. HorizontalScrolling, this option indicates if the user can scroll horizontally inside the MessageBox when the content is larger than the content area. |
- Since:
- 1.30