How to hide an uploaded video when there is no Video Data.

Hi, so I’ve used the wix tutoria l that teaches you how to collapse a video when there is no item data found. However the tutorial is only for video urls. Does anyone know how to hide an uploaded video/image? Here is my code:

$w.onReady(() => {
    $w("#dataset3").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#dataset3").getCurrentItem();
 if (!item.video) {
 // Checks if the current item has a value in the "video" field
 // Collapses the video player if there is no value for "video"
            $w("#videoPlayer1").collapse();
        }

    });
});
//========================= FOR VIDEO ↑ ========== FOR IMAGE ↓
$w.onReady(() => {
    $w("#dataset3").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#dataset3").getCurrentItem();
 if (!item.video) {
 // Checks if the current item has a value in the "video" field
 // Collapses the video player if there is no value for "video"
            $w("#image3").collapse();
        }

    });
});

My layout is this:

I have a repeater with a video & and an image on it. I want the video and/or image to collapse if no items can be found for them in the data collection.

I think I’m close, I just can’t seem to to find a work around.


Thanks in advance.

I have the same problem :confused:
Please guys how has idea to

The code posted by Alex should do the work.

The code work with URL FIELD types
But video field types not work
Get error messages

Post your code

$w ( “#dataset1” ). onReady (() => {
const item =
$w ( “#dataset1” ). getCurrentItem ();
if ( ! item . video ) {
$w ( “#videoPlayer1” ). collapse ();
}

}); 

});

You have an extra }) , unless this is the closure of the $w.onReady() that you haven’t posted.
Anyway it looks like the error you posted is not related to this code.

The message of the error speaks about the smallness of the felid
Could you write the correct formula
Please
Thanks

Please copy&paste it (it’s hard to read t this way).

  • Use a single $w(“#dataset1”).onReady() and put everything in it. There’s no reason to repeat it 7 times.
  • I can see you’re not using the getcurrentItem() correctly.

it should be something like:

const item = $w("#dataset1").getCurrentItem();
const [image1, image2, image3] = [item.image1, item.image2, item.image3];

or even shorter:

const item = $w("#dataset1").getCurrentItem();
const {image1, image2, image3} = item;
$w.onReady(function () {
 
      $w("#dataset1").onReady(() => {
 const item = $w("#dataset1").getCurrentItem();
const [video, image1, image2, image3, image4, image5] = [item.video, item.image1, item.image2, item.image3, item.image4, item.image5];
 if (!item.video) {
     $w("#videoPlayer1").collapse();
 }
else if (!item.image1) {
    $w("#image1").collapse();
}
else if (!item.image2) {
    $w("#image2").collapse();
}
else if (!item.image3) {
    $w("#image3").collapse();
}
else if (!item.image4) {
    $w("#image4").collapse();
}
else if (!item.image5) {
    $w("#image5").collapse();
}
 else {
     $w("#videoPlayer1").expand();
     $w("#image1").expand();
     $w("#image2").expand();
     $w("#image3").expand();
     $w("#image4").expand();
     $w("#image5").expand();
 }
 

    });
});

get the error
Wix code SDK error: The “src” property cannot be set to “”. It must be a valid image URL starting with “http://”, “https://” or “wix:image://”, or a valid video URL starting with “wix:video://”.

The only work around I can think of is finding a way to upload a video through wix to a host server, then somehow retrieving that url and applying it to the wix database. I am not sure how to that though :confused:

Was there ever a follow up to this or did you get it working. I am in the same boat. I can get images to collapse no problem but not videos linked to a dataset.

I don’t know what console.log($w(“#videoplayer1”).src) print to the empty data coming from the collection, but try it yourself, for example if it’s print undefined or null or blabla . Write code like this.

if($w("#videoplayer1").src===blabla){
$w("#videoplayer1").collapse()
}else{
$w("#videoplayer1").expand()
}

As I show in the picture below.

I have tried every bit of code I can find and none seem to work as it is based on URL video, not video added to the collection by uploading it.