How do I hide a button in a repeater's item when its dB field is empty?

Hi there.

I have searched several methods in the forum to solve this but none worked for me.
I have a repeater of client reviews connected to a dB named “Quotes”. One of the elements in the item is a button taking the user to the client’s webpage. The link comes from a “link” column in the dB.

Some of the reviews are of people without webpages. Their “link” field is empty in the dB.

In that case, the button is supposed to be inactive and get its design from the “inactive” design in the settings but that doesn’t work. So I was looking for a code that will hide the button if its field is empty.

I tried “isEmpty”.
I tried " wixData.query"
I tried “getCurrentItem()” of the dataset"
and other variations…

None worked.

The only code that came close is this one:

$w.onReady(function () {
 $w('#dataset1').onReady( () => {
 let linkField = $w('#dataset1').getCurrentItem().link;
	if (linkField) {
	        $w("#button8").collapse();
            }
        });
});

But it collapses the buttons in all items. I need that only the buttons in the specific items that don’t have a link will collapse.

Anyone can give me some directions?
Thank you! :slight_smile:

Adding:

I tried to play with the " onItemReady " function of the repeater but didn’t quite understand the process.

Can you post your onItemReady() code?
This will make it more easy to adjust it and readable for you to understand :slight_smile:

Kind regards
Kristof.

Here is what I got so far:

$w.onReady(() => {
  $w('#repeater1').onItemReady(($wdataset1, Quote) => {
 const urlEmpty = !Quote.url
 if (urlEmpty)
        $wdataset1('#button8').collapse()
  })
});

It makes all buttons collapse.

Got this far, but still, the button collapses in all items:

$w.onReady(() => {
  $w('#repeater1').onItemReady(($item, itemData, index) => {
	let url = itemData.url;
 	if (url === "" || url === null || url === undefined) {
 		$item('#button8').collapse();
	}
  })
});

What am I doing wrong?

Are you sure that itemData.url actually contains a url? Since you say that the button collapses for all items, it seems from your code that either itemData.url is empty for all items, or you are using the wrong item field.

As you stated in your original post " The link comes from a “link” column in the dB." Maybe the field you want is link ?

Thank you.
Assuming the column name is “link”, how would you change the code accordingly?
I tried several variations but no success.

@contact13073 Instead of:

let url = itemData.url;

You want something like thisA:

let url = itemData.link;

@yisrael-wix
Fantastic. Thank you. I changed the $item as well by mistake.

Can you post the final code?