Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Extended Control - call custom function

Hello Experts,

I've written a custom control that extends ToolPopup.

"use strict";

  jQuery.sap.declare("controls.MyToolPopup");

  sap.ui.ux3.MyToolPopup.extend("controls.MyToolPopup", {

      renderer: {},

      myFunc : function() {

          //TODO:

      },

      onAfterRendering: function() {

          var $this = this.$();

      

          var sID = this.getId();

      

          var title = $this.find('.sapUiUx3TPTitle');

          title.removeClass("sapUiUx3TPTitle");

          title.addClass("customClassUiUx3TPTitle");

              title.append('<a id="' + sID + '-close" href="#" onclick="myFunc()">X</a>');

      }

  });

The control has additional html 'a' tag and I need to call a custom function when clicking on the link.

How can I call the custom function (myFunc) from the onclick event of the 'a' tag?

Regards,

Omri

replied

Solved it on my own:

  "use strict";

 

  jQuery.sap.declare("controls.MyToolPopup");

 

  sap.ui.ux3.ToolPopup.extend("controls.MyToolPopup", {

      renderer: {},

      myFunc : function() {

          console.log("OK!");

      },

 

     

      onAfterRendering: function() {

          var that = this;

          var $this = this.$();

       

          var sID = this.getId();

       

          var title = $this.find('.sapUiUx3TPTitle');

         

          title.removeClass("sapUiUx3TPTitle");

          title.addClass("customClassUiUx3TPTitle");

              title.append('<a id="' + sID + '-close" href="#"">X</a>');

           $("#" + sID + "-close").on("click",function(){

            that.myFunc();

              });

         

      }

  });

However if someone has a cleaner solution...

Regards,

Omri

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question