cancel
Showing results for 
Search instead for 
Did you mean: 

Adding event in custom control that blocks default event

davidsigleinit
Explorer
0 Kudos
331

Hello all,

I have a custom control that extends from sap.m.StandardTile and I want to add an enabled property to it, so I can prevent the "press" event from firing if enabled = false.

My trouble now is that in this example of adding a custom event to a custom control that extends the default Button: Documentation - Demo Kit - SAPUI5 SDK (ondemand.com) .

Where does the function this.fireHover() come from? I checked the api reference for Button and there is no such thing as .fireHover() in it. So is this function that is the implemented in the custom control and is just missing in this example or am I missing something?

In my use case, I would simply think that I can override the press method like so:

and define the new enabled property like so:

However the press event still fires, even if I set the new enabled propert to enabled = "false" in the XML.

Any help would be greatly appreciated.

Cheers!

Accepted Solutions (1)

Accepted Solutions (1)

AlexNecula
Active Contributor

Hi, I didn't test this, but you can try to overwrite firePress like this:

firePress: function () {
    if (this.getEnabled()) {
         StandardTile.prototype.firePress.call(this);
    }
}

Answers (1)

Answers (1)

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

What is the reason for extending sap.m.StandardTile in the first place? The StandardTile is deprecated since UI5 1.50. Consider using sap.m.GenericTile instead which supports the "Disabled" state among others out of the box. If the GenericTile is disabled, no press event will be fired.

<GenericTile xmlns="sap.m" state="Disabled" pressEnabled="false">
<!-- ... -->

Sample: https://ui5.sap.com/#/entity/sap.m.GenericTile/sample/sap.m.sample.GenericTileStates/code
API Reference: https://ui5.sap.com/#/api/sap.m.GenericTile