Skip to Content
avatar image
Former Member

How can I locate the js event handler code by inspecting the html element?

Say I'm on a UI5 application page, there's a button, and I would like to find out which event handler logic is binded to this button, without searching through the controller js file by keyword, how can I locate the js event handler code by inspecting the html element? I tried, but there's no html attribute like onclick='' in the html. Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 29, 2015 at 07:12 PM

    SAPUI5 Diagnostics tools would do it. But there are api's that would do it very much simpler than that. When you inspect the html, just find the runtime id of the control.

    • open the console tab in debugger tools
    • $("#<control-id>").control(0); // gives the sapui5 instance of the control
    • Expand the mEvenRegistry
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2015 at 06:17 AM

    Open dev tools (cntrl + shift + I)

    Open Diagnostic tool (ctr +shift + alt +s)

    go to Control tree

    select the control

    go to breakpoints

    select fireEvent (or any particular event like change etc.)

    debug till the call (step inside call and you will see controlelrs code like PayChangeForm.controller below) There might be multiple event handlers but usually it is only one


    sdn.PNG (75.6 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Can you try this in the console.

      sap.ui.getCore().byId("buttonid").mEventRegistry["press"][0].fFunction

      here buttonid - Id of the button

      press - is the event i have attached to the button.

      When you do this,

      You will be getting the event .

      Hope this will be of some help.

      Capture.PNG (182.8 kB)
  • Oct 28, 2015 at 04:12 AM

    hi Tylr

    Javascript event handler is track in the event.

    maybe this JSBin can help you.

    JS Bin - Collaborative JavaScript Debugging

    Click on Inspect Button

    Thanks

    -D

    Add comment
    10|10000 characters needed characters exceeded