I’m trying to add a repeater of buttons on my product page for size selection. As shown here:
The goal is to have the background color of the button indicate the option selected.
I can get it to work somewhat. So using the image above as an example, if I click on Large next, it works as needed. It always works when I click on a higher option.
The problem is when I click on a lower option, the higher option won’t change. If I go further and click on Small below, all three are selected.
I can’t for the life of me figure out why this is. Below is my code. Any suggestions?
export function sizeRepeater_itemReady($w, itemData, index) {
$w('#sizeButton').label = itemData.description; // button label to get populated with size options
$w('#sizeButton').onClick( (event) => {
$w("#sizeRepeater").forEachItem( ($w) => {
$w('#sizeButton').style.backgroundColor = "#ffffff" //RESET: after a button is clicked, change button backgrounds to white
})
$w('#sizeButton').style.backgroundColor = "#b6f3e8"; //update the selected option background to color
$w('#productSize').text = $w('#sizeButton').label;
})
}
Thanks!