on 10-28-2015 3:34 AM
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would do the following:
Hope this helps
all right, after overclocking my brain with bulletptoof coffe here is some snippet:
var walkThroughUI = function(root, fnCallback) {
if (!root)
return;
fnCallback(root);
$.each(root.findAggregatedObjects(true), function(i, control) {
fnCallback(control);
});
};
var includeByEvent = function(__fn) {
return function(element) {
$.each(element.mEventRegistry, function(item, i) {
var aEventListeners = element.mEventRegistry[item], oInfo;
debugger;
if (aEventListeners) {
aEventListeners = aEventListeners.slice();
for (var i = 0, iL = aEventListeners.length; i < iL; i++) {
oInfo = aEventListeners[i];
if(oInfo.fFunction === __fn)
{
console.log(element.getId() + ": " + item);
}
}
}
});
};
};
you set a breakpoint anywhere you in your controller (onInit is fine) and in console type
walkThroughUI(this.getView(), includeByEvent(this.YOUR_EVENT_HANDLER_FUNCTION) );
that will print you an ID of element and name of the event, like
__xmlview0--Reset: press
minified version
var walkThroughUI=function(n,e){n&&(e(n),$.each(n.findAggregatedObjects(!0),function(n,t){e(t)}))},includeByEvent=function(n){return function(e){$.each(e.mEventRegistry,function(t,c){var i,o=e.mEventRegistry[t];if(o){o=o.slice();for(var c=0,r=o.length;r>c;c++)i=o[c],i.fFunction===n&&console.log(e.getId()+": "+t)}})}};
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.