on 02-23-2017 3:17 PM
Hello Experts,
there is a new property of sap.m.Dialog, called escapeHandler. Does anyone know, how-to use it? It is available since 1.44. We're on 1.44.7, but could not make it working. It is a property and not an event handler btw.
The Dialog.fragment.xml part:
<Dialog title="{i18n>chooseWS}" contentHeight="100%" contentWidth="100%" stretch="true" verticalScrolling="false" escapeHandler="mayTheForceBeWithMe">
The Controller:
this._oDialog = sap.ui.xmlfragment("xxx.xxx.xxxx.xxx.Dialog", this); this._oDialog.setModel(this.getModel("i18n"), "i18n");
this._oDialog.open();
...
mayTheForceBeWithMe: function(oPromise) {
if (!this.oFilterEntry || this.oFilterEntry.workspace == "") {
oPromise.reject(); } else {
oPromise.resolve();
}
},
...
Function mayTheForceBeWithMe is not invoked.
Thank you
Hello Atilla,
I checked the issue and i found that if the dialog is created in the XML Fragment then it does not work. Where as if it is created in javascript controller it works. I checked the code of Dialog controller and this is the code
if (typeof oEscapeHandler === 'function') {
// create a Promise to allow app developers to hook to the 'escape' event
// and prevent the closing of the dialog by executing the escape handler function they defined
new window.Promise(function (resolve, reject) {
oPromiseArgument.resolve = resolve;
oPromiseArgument.reject = reject;
that.currentPromise = oPromiseArgument;
oEscapeHandler(that._getPromiseWrapper());
})
.then(function (result) {
that.close();
})
.catch(function () {
jQuery.sap.log.info("Disallow dialog closing");
});
} else {
this.close();
}
So there the oEscapeHandler needs to be function . I think this could be a bug from why checks for the type , but yes the way for you to make it work is using in javascript controller .
Thanks and Regards,
Veera
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The escapeHandler can now be assigned in XML: https://stackoverflow.com/a/64909600/5846045 (Since 1.86)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Boghyon,
good to hear, I'll keep this in mind for the next freestle app implementation.
Thanks
Hi boghyon.hoffmann,
Thank you for your detailed explanation, could you please clarify few doubts since I'm new to UI5 coding:
1. Why do we have use the dot '.' infront of the controller method name in order to call it, while other methods in the view works fine without it?
2. Could you please provide a sample code snippet on how pEscapePending.resolve() or pEscapePending.reject() is called?
Thanks in advance.
Hi Attila, as Veeraraghavan explained, onEscapeHandler is not working properly on XML fragments, I just struggled with this issue myself. However I wanted to post a workaround in case anyone else has this problem:
1.- In the Dialog.xml.fragment, assign an ID to your Dialog:
<Dialog id="dlg" title="{i18n>chooseWS}" contentHeight="100%" contentWidth="100%" stretch="true" verticalScrolling="false" escapeHandler="mayTheForceBeWithMe">
2.- After fragment instanctiation, attach an onClose event handler to your Dialog "dlg":
if(!this._oDialog){
this._oDialog = sap.ui.xmlfragment("xxx.xxx.xxxx.xxx.Dialog", this); this._oDialog.setModel(this.getModel("i18n"), "i18n");
var that = this;
var dlg = sap.ui.getCore().byId("dlg");
dlg.attachAfterClose(function() {
/*Here implement your logic to determine if the dialog should be closed or not, IE: if an item in your dialog was selected or not, or whether an input has been filled with data or not. In case you determine it should not be closed, then call this._oDialog until your condition is met.*/
});
}
Hope it helps.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If you have created the dialog via XML fragment you can use the following workaround to handle the escape
var oFragmentId = "myFragId", oFragmentName = "com.abc.fragment.myPopup";
if (!this.myPopup) {
/* _createFragment is a base controller function i made to create an xml fragment */
this.myPopup= this._createFragment(oFragmentId, oFragmentName);
/* Since i use XML view ,We will attach the escape event handler in controller level */
this.myPopup.setEscapeHandler(function(o) { o.reject(); });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank You Ramees. Solved with JS based approach, but next time I am gonna use your approach.
Sample code is avilable in explored app
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
96 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.