Skip to Content
0

sap.m.Dialog escapeHandler how-to

Feb 23, 2017 at 03:17 PM

664

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Veeraraghavan Narasimhan
Feb 23, 2017 at 09:16 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Srikanth KV Feb 23, 2017 at 04:53 PM
0

Sample code is avilable in explored app

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you for the snippet Srikanth

0
Edgar Peña Jan 21 at 02:23 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
ramees rahath Jul 04 at 05:31 AM
0

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(); });

Share
10 |10000 characters needed characters left characters exceeded