Himanshu Arora
Himanshu Arora

Reputation: 29

Why can't I find control using sap.ui.getCore().byId()?

I'm trying to access an input control in the controller but I'm not able to fetch it.

I'm using

sap.ui.getCore().byId("id of the input");

Upvotes: 1

Views: 419

Answers (3)

Chris Neve
Chris Neve

Reputation: 2424

Try the following:

this.byId('controlId')

Or:

this.getView().byId('controlId')

See Difference Between this.getView().byId(), this.byId(), and sap.ui.getCore().byId()

Upvotes: 1

Tina Chen
Tina Chen

Reputation: 2030

https://openui5.hana.ondemand.com/#docs/guide/91f28be26f4d1014b6dd926db0e91070.html Hope this doc will help you.

You should use relative navigation(this.getView().byId('myId')). Absolute Navigation(sap.ui.getcore().byId('myId')) is not recommended, since that will not work anymore if you change like local project to FioriLaunchpad.

I think the source code of byId of Controller and createId of View explains a lot.

Upvotes: 1

codemania23
codemania23

Reputation: 1071

I faced a similar issue when I started using UI5. The id is not the same anymore because Sap UI5 dynamically concatenates some other properties to your id so it will be different. Hope this helps. try finding out the id after it has been changed by the resources.

Upvotes: 1

Related Questions