cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript Code within XML View

former_member193947
Participant
0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

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...

former_member484715
Contributor
0 Kudos

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.

junwu
Active Contributor
0 Kudos