Hiding a button in some items of a repeater

Hi all.

I have a repeater where I am showing some text, an image and a button in each item.

In some items, I want to hide the button.

I have collapsing the button when the button text is undefined (ie the collection has no entry for the button text) inside both onItemReady( ) and forEachItem() functions but it’s not working…and I think its because you simply cannot collapse an element in those functions.

Does anyone have any idea what else to try?

Simon.

@simon9978 You can achieve what you want with those functions, but you have to use the repeated item scope selector ($item) to refer to the particular button of
each repeated item that is being evaluated.

$w.onReady( function () {
  $w("#myRepeater").onItemReady( ($item, itemData, index) => {
    // calling the field name that you're checking "buttonText"
    if (itemData.buttonText === undefined){
      $item("#button").collapse();
    }
  });
});

Check out the introduction in the repeater documentation for a thorough description of this.

Perfect answer Anthony. I had not read the intro section in repeaters and it all makes sense now.

Thanks!
Simon.