This blog tells you about types of dialog controls and how to use in SAP UI5
new sap.ui.commons.Dialog())
. Next, you set the properties for the title and the content, make settings for the size and define other property values.alert()
, confirm()
, and show()
. Syntax for alert() :-
Syntax for confirm() :-
Syntax for show() :-
<!DOCTYPEHTML>
<html>
<head>
<title>Welcome | SAPUI5 Demo ::Dialog controls</title>
<scriptsrc="resources/sap-ui-core.js"id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_goldreflection">
// Available Themes: sap_goldreflection, sap_platinum and By Default: High Contrast Black
</script>
<!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->
<script>
function dispAlert() { //Display simple Alert Message
sap.ui.commons.MessageBox.confirm("Are you want to display message?",rCallAlertBack, "Confirmation");
returnfalse;
}
// to call the above function, we create a simple button
new sap.ui.commons.Button({text:"Show Message", press : dispAlert}).placeAt("content1");
// to get back the user selection from the above function
function rCallAlertBack(rValue) {
if(rValue) //If User presses 'Ok'
{
sap.ui.commons.MessageBox.alert("Welcome to SAPUI5.\n You're now viewing a Simple alert message.",'',"Congrats!");
returnfalse;
}
else // If the user presses 'Cancel'
{
sap.ui.commons.MessageBox.alert("You are refussed to display the message",'',"Notification");
}
}
jQuery.sap.require("sap.ui.commons.MessageBox"); // this is required since there is no direct access to the box's icons like MessageBox.Icon.WARNING
function fnCallbackMessageBox1(sResult1) {
if(sResult1=='OK') {
sap.ui.commons.MessageBox.show("You are not authorized to delete this content.\n Please check your access",
sap.ui.commons.MessageBox.Icon.WARNING,
"Warning",
[sap.ui.commons.MessageBox.Action.OK,sap.ui.commons.MessageBox.Action.CANCEL],
'', sap.ui.commons.MessageBox.Action.OK);
}
else {
sap.ui.commons.MessageBox.alert("You are refused to display the message",'',"Notification");
}
returntrue;
}
// a callback that will be called when the message box is closed again
function fnCallbackMessageBox(sResult) {
if(sResult=='OK') {
sap.ui.commons.MessageBox.show("You are not authorized to delete this content.\nCheck Access and try again",
sap.ui.commons.MessageBox.Icon.INFORMATION,
"Notification", [sap.ui.commons.MessageBox.Action.OK,sap.ui.commons.MessageBox.Action.CANCEL],
fnCallbackMessageBox1,sap.ui.commons.MessageBox.Action.OK);
}
else {
sap.ui.commons.MessageBox.show("Data deleted successfully!\n", sap.ui.commons.MessageBox.Icon.SUCCESS,"Sucess",
[sap.ui.commons.MessageBox.Action.OK], '', [sap.ui.commons.MessageBox.Action.OK]);
}
returntrue;
}
function openMessageBox() {
/* sap.ui.commons.MessageBox.Icon.WARNING or ERROR or INFORMATION OR CRITICAL OR SUCCESS OR QUESTION
For the buttons to be displayed, you can use values such as sap.ui.commons.MessageBox.Action.YES or sap.ui.commons.MessageBox.Action.NO. */
// open a fully configured message box
sap.ui.commons.MessageBox.show("You are not authorized to delete this content.\nCheck Access and try again",
sap.ui.commons.MessageBox.Icon.ERROR,"Error",
[sap.ui.commons.MessageBox.Action.OK,sap.ui.commons.MessageBox.Action.RETRY],
fnCallbackMessageBox,
[sap.ui.commons.MessageBox.Action.OK,sap.ui.commons.MessageBox.Action.RETRY]);
}
// to call the above function, we create a simple button
new sap.ui.commons.Button({text:"Delete Content", press : openMessageBox}).placeAt("Content2");
</script>
</head>
<bodyclass="sapUiBody">
<divid="content1"></div>
<br/>
<divid="Content2"></div>
<br/>
</body>
</html>