user3800987 user3800987 - 4 months ago 48
HTML Question

Image Buttons onchange when clicked in SAPUI5?

How can I change the image button when clicked? It should change to other image button.

var offButton = new sap.ui.commons.Button({
id : "offIcon",
icon : "img/off.png" ,
press :function(e) {
alert("clicked");
var noButton = new sap.ui.commons.Button({
id:"noIcon",
icon : "img/no.png" ,
});
noImage.addStyleClass("noButtonImage");

Answer

You are defining two buttons, this might not work, check this:

var offButton =  new sap.ui.commons.Button({
        id : "offIcon",
        icon : "img/off.png" ,
        press :function(e) { 
                var myBtn = sap.ui.getCore().byId("offIcon");
                myBtn.setIcon(''); // this removes the icon
               }
        });

On Off Example:

var offButton =  new sap.ui.commons.Button({
        id : "offIcon",
        icon : "img/off.png" ,
        press :function(e) { 
                var myBtn = sap.ui.getCore().byId("offIcon");
                if (myBtn.getIcon() == '' || myBtn.getIcon == 'null') {
                  myBtn.setIcon('img/off.png');
                } else {
                myBtn.setIcon(''); // this removes the icon
                }
               }
        });
Comments