TVJS TVML toggle button

206 views Asked by At

I have a button, I would like to be able to click the button and the image change to something else, sounds simple.

 <buttonLockup toggle="true">
        <badge src="resource://button-rate-off" class="whiteButton" />
        <title>Add to Favourites</title>
      </buttonLockup>

Should change to:

 <buttonLockup toggle="true">
        <badge src="resource://button-rate-on" class="redButton" />
        <title>Remove from Favourites</title>
      </buttonLockup>

In my Presenter.js I have a load function that can detect I've selected the item:

load: function(event) {
    console.log(event);

    var self = this;
    var ele = event.target;
    var toggle = ele.getAttribute("toggle");

    if (toggle)
    {
           console.log(ele);
           var badge = ele.getElementsByTagName("badge").item(0);
           console.log(badge);
           badge.src = "resource://button-rated"; // Doesn't change
    }
},

Any ideas on how to get it to change?

1

There are 1 answers

0
Chris On BEST ANSWER

Ok, so this seems to work, but I get strange re-layout issues of sections above:

var isTrueSet = (toggle === 'true');
        var badge = ele.getElementsByTagName("badge").item(0);
        if (isTrueSet == true)
        {
            badge.setAttribute('src', 'resource://button-rated'); 
        } else {
            badge.setAttribute('src', 'resource://button-rate');
        }
        ele.setAttribute('toggle', !isTrueSet);