Hiding a Video Player When There Is No Video to Play

I am trying to hide a videoplayer on a page when there is no video. It’s attached to a dataset that appears on the page. One of the fields displayed on the page is a video url. On some entries, there is no video, so I don’t want the videoplayer to appear . I have tried the code that appears on this page:

That is the suggestion from Wix helpdesk.

This is the code and it does not work:

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

I’ve tried and tried and nothing works. I’ve tried alternate code suggestions that don’t work.

What am I doing wrong. Some default video (skyline video) shows on the page on the entries where there is no video. I think that is the problem. Here is the page.

https://gthompson272.wixsite.com/irss-usa/newsold

code
question

It seems that on the page you shared you’re using a repeater, which would require slightly different code than the one shared above.

You’re probably looking for something similar to this

$w.onReady(function () {
    $w("#datasetID").onReady(() => {
        $w('#repeaterID').onItemReady(($item, itemData, index) => {
            if (itemData.videoKey) {
                $item('#videoPlayerID').show();
            } else {
                $item('#videoPlayerID').hide();
            }
        })
    });
});

You’ll need to change out the datasetID, repeaterID and videoPlayerID for the IDs of the elements on your page.

You can find your element IDs here when you have selected them.
Screenshot 2023-11-14 at 12.16.41

itemData.videoKey will also need updating to include the key of the video field in the database. When editing the field in the collection, you’ll find the key here:
Screenshot 2023-11-14 at 12.18.43

So for example, it might be itemData.image based on the key I have above.

Hope this helps :slight_smile: Good luck!