on 02-07-2019 8:54 AM
I am new in UI development and looking for a help on below issue. I have created a SAP UI5 project which has one button defined in view file and function defined in controller file which gets called on press event of button.
I have a requirement to click button B1 from outside of UI5 framework and also invoke controller function defined on press event of button.
Can someone please suggest how this can be done.
Thanks
Hi Swati Garg,
You can directly access the button and call firePress() method right?
But you cannot directly access the button outside with the id you have given inside the view.. UI5 framework will generate a different ID based on the component name, view name and the button id. using that id you need to get the button instance.
If the button id is "ButtonCustID" then the UI5 generated will be "__ComponentName---ViewName--ButtonCustID".
sap.ui.getCore().byId("").firePress("__ComponentName---ViewName--ButtonCustID");
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
My first though was to solve this as you correctly said. But after that , I read again the issue and noticed that:
"I have a requirement to click button B1 from outside of UI5 framework".
It could mean that in the right moment he needs to fire the click event, the controller or even the button could be not loaded yet.
That make a little sense if we see that he wants to "invoke the controller".
So I think in this case the global generated ID by SAPUI5 as you suggested couldn't be the solution.
Do you agree?
Yeah I agree, but you can check the old question posted by OP where the OP wants to replicate the actions that there performed by the user which were saved somewhere.. So I assumed that OP has already opened the app and performing some admin action to run through the actions performed by the user..
So many assumptions I made here 😄 maybe Swati Garg can tell us the actual scenario.
It's just the button id.. did you try to use the code that I mentioned above?
document.getElementById('yourbuttonid').click()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what's your scenario?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need to capture user actions performed on sap ui5 web page and playback same after sometime. So if user entered a text and clicked on button then I want to playback same from outside. I am able to capture and playback input field but click of button doesn't call function defined on press event in controller file during playback. So i need to know how to invoke controller function from outside. Below code clicks the button.
var targBtn = document.querySelector ("#" + target.id); //target.id is id of control element.
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targBtn.dispatchEvent (clickEvent);
My code to capture and playback is written in .Js file and I have injected this file in index file of sapUI5 app.
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.