How to override/disable "escapeHandler" of "Dialog" via XML-template in UI5?

Viewed 1422

I know to override in UI5 the default behavior of sap.m.Dialog's escapeHandler via controller, e.g.:

this._oDialog.setEscapeHandler((oEscapeHandler) => {
    oEscapeHandler.reject();
});

The question is it possible to provide an alternative escapeHandler behavior via XML-template without using of setEscapeHandler?

Ideally, it should be something like escapeHandler = "none/customFunction", e.g.:

<Dialog
    id = "authDialog"
    title = "{i18n>DIALOG_TITLE}"
    type = "Message"
    escapeHandler = "%CUSTOM_ESCAPE_HANDLER%">
</Dialog>

Particularly, I want to disable a Dialog closing on Esc button press and to do it in an elegant, declarative manner via XML-template, e.g. escapeHandler = "none".

2 Answers

There was a new commit (merged today) that enables assigning controller function to escapeHandler. With that, the below code is now possible:

<Dialog xmlns="sap.m"
  id="authDialog"
  title="{i18n>DIALOG_TITLE}"
  type="Message"
  escapeHandler=".handleEscape"
>
handleEscape: function(pEscapePending) {
  // Depending on the use case, call pEscapePending.resolve() or pEscapePending.reject() to overwrite the default behavior.
},

The fix should be available with the 1.86 release.

I solved this issue by putting the property escapeHandler = "customFunction" and then having a function with no implementation in the controller. Basically in customFunction I had a comment explaining that this is used to override the default escape behaviour.

Related