Question:
How can I hide the image in a repeater when the dataset field is empty? Currently, when the “Samenwerking Logo” field in my dataset is empty, a white placeholder or blank image is still displayed. I want the image to be completely hidden if no logo is available for that item.
Product:
Wix Editor (Velo Code)
What are you trying to achieve:
I’m trying to display an image in a repeater only if the dataset field (for a logo) contains a valid image URL. If the dataset field is empty or doesn’t have a logo, the image should be hidden entirely, without showing any placeholders or white space.
What have you already tried:
- I’ve set up the repeater and connected the image field to the dataset (“Samenwerking Logo”).
- I’ve used Velo code to attempt to show/hide the image based on the field’s data.
- I tried resetting the image
src
tonull
and using.hide()
to remove the image, but I still get white placeholders or an empty image appearing. - I’ve reviewed Wix forums and articles related to repeaters and dynamic images, but haven’t found a solution that works.
Additional information:
- My repeater ID is
#repeater1
, the dataset ID is#dataset1
, and the image ID is#image164
. - I am using the following code to hide the image, but it still shows a white placeholder when the logo is missing:
$w.onReady(function () {
$w("#dataset1").onReady(function () {
$w("#repeater1").onItemReady(($item, itemData) => {
if (itemData.samenwerkingLogo) {
$item("#image164").src = itemData.samenwerkingLogo;
$item("#image164").show();
} else {
$item("#image164").src = null;
$item("#image164").hide();
}
});
});
});
I’ve also checked that no default placeholder images are set for the image element. What should I adjust to ensure no white placeholder appears when the field is empty?