cancel
Showing results for 
Search instead for 
Did you mean: 

Detaching / Removing Event Listener UI5

Former Member
0 Kudos

I have a workflow-like requirement for my app and I need to change the event handler of a common button depending on the status of the workflow.

Research revealed only one example, which stores the event handler function in a variable: Correctly removing event listeners in SAPUI5

Looking into the API I found it's also possible without use of a variable like this:

btn.detachPress(btn.mEventRegistry.press[0].fFunction);

btn.attachPress(oController.onMyNewHandlerPress);

Buttons generally only have one intended press event handler, so referencing press[0] seems OK to me.

This post should let the community validate this technique as an alternative to the one in the link above, or perhaps propose an even better one.

Possibly the OpenUI5 team might like the idea to add to the API a detachPress() - no args, or detachAllPress(), to just blanket reset all event handlers.

Thanks

Jason

Accepted Solutions (0)

Answers (0)