Working with Dialog Controls in SAP UI5
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() :-
<!DOCTYPE HTML>
<html>
<head>
<title>Welcome | SAPUI5 Demo ::Dialog controls</title>
<script src=“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”);
return false;
}
// 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!”);
return false;
}
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”);
}
return true;
}
// 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]);
}
return true;
}
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>
<body class=“sapUiBody”>
<div id=“content1”></div>
<br/>
<div id=“Content2”></div>
<br/>
</body>
</html>









nyc one 🙂 🙂
well explained! expecting few more blog post on UI5
good one 🙂 thank you
good! Thanks.
Thanks.
Very useful one, Thanks
How to set a custom header for dialog box in ui5?
Hi Tharun,
If you replace the "Warning" to your desired text - it will be display as the header for the dialog box in UI5.
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);
Let me know if this works..
Thanks !
Bharath
Hi,
How can we increase the size of the message box. Right now I am displaying a table in a message box and its not looking good as the text in every column field is appearing in next line while trying to fit in the message box.
Is there anything I can do to increase the size.
Regards,
Anupriya
Hi Anupriya,
Try using the syntax - it creates a message Box similar to the alert window.
sap.ui.commons.Dialog({
modal : true,
// a percentage width does result in an ugly vertical slider in Chrome
width : '600px',
content : oContent,
closed : destroyDialog
});
Thanks,
Bharath
Hi,
is it possible to use custom button text with sap.ui.commons.MessageBox.confirm. For example instead of Yes and No, I could set the button text in my native language?
You may extend this.
Can you explain how to add button text on dialog dynamically?
Please create a new Discussion with your Question.
Regards, Mike (Moderator)
SAP Technology RIG
Hi Experts,
Is there a way to stop the drag feature of the dialog.
Regards.
Loki
you can try these
1. resizable:false
or
2. try fixing the size contentWidth: "550px" contentHeight: "300px"