Skip to Content
0

Javascript Code within XML View

Jan 11 at 06:46 PM

54

avatar image

Hello,

I am trying to find a way to insert Javascript Code within XML View. Below code is an example, where we need to display a custom tooltip based on a custom or third party library. We can do this in controller file by adding event delegate. But for having tooltip for many UI controls, having separate methods might take more code/time. Whereas, if there is a way within XML, it will be simple to invoke a single line additional code. Please point with some examples as well.

        new Button({
          text: "mouseover Here",
          icon: "sap-icon://cursor-arrow",
          iconFirst: false,
          type: ButtonType.Transparent,
          tooltip: new MyTooltip({
            text: "Awesome!"
          }),
        })

Thanks and Regards.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

avatar image
Former Member Jan 12 at 04:04 AM
-1

Try this approach...

For each button, you can add an `id` in the XML file. In the OnInit Method, you can add the tooltips with a single line of code like below...

this.byId("idbtn").setTooltip("This is Test") 

Also if you have multiple views which need tooltips you could move this code into a common utility file for re-usability...

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Jan 11 at 09:52 PM
0
Share
10 |10000 characters needed characters left characters exceeded
Arjun Biswas Jan 12 at 04:03 AM
0

Hi,

It is not a standard / good practice to write your JS code inside an XML view, as XML views support strictly an MVC architecture. I would recommend that, you set the tooltip for your controls in the init function of your controller.

Regards,

Arjun Biswas.

Share
10 |10000 characters needed characters left characters exceeded