Well, it is difficult to say what’S going on on your side, since you do not provide any details on your setup.
What you should first check..???
-
- Add a dataset to your page and connect it to your collection.
-
- Add a Video Player and connect it to the URL field.
-
- Open the code editor for your page.
-
- Copy and paste the code below.
I think all of that you have done and checked already.
Your current STARTING code should be right now…
//-------------- USER-INTERFACE -----------------
const DATASET = 'dtsOurWork';
$w.onReady(()=> {console.log('Page is ready...');
$w(`#${DATASET}`).onReady(()=> {console.log('Dataset is ready...');
const item = $w(`#${DATASET}`).getCurrentItem(); console.log('ITEM: ', item);
//...more code
//...more code
//...more code
//...more code
});
});
Your dataset will be connected to your Or-Work-Database i think.
Inside your database you will have several different FIELDS (PROPERTIES) including → a FIELD of TYPE → URL <–. This field will include the right VIDEO-URL.
Like already shown in example → the following code-part do exactly what you want to achieve. It sets a IF-CONDITION to check wether there is URL available or not.
if (!item.video) {
// Collapses the video player if there is no value for "video"
$w("#videoPlayer").collapse();
}
If VIDEO-URL not available → it will collapse the chosen Videoplayer.
So let us UPGRADE your code to make things a little bit cleaner…
//-------------- USER-INTERFACE -----------------
const DATASET = 'dtsOurWork';
const vidPLAYER1 = 'videoPlayer1';
const vidPLAYER2 = 'videoPlayer2';
//-------------- USER-INTERFACE -----------------
$w.onReady(()=> {console.log('Page is ready...');
$w(`#${DATASET}`).onReady(async()=> {console.log('Dataset is ready...');
const item = $w(`#${DATASET}`).getCurrentItem(); console.log('ITEM: ', item);
if (!item.video) {console.log('...no video-URL found...');
await $w(`#${vidPLAYER2}`).hide('fade');
$w(`#${vidPLAYER2}`).collapse();
}
else {console.log('...video-URL found...');
$w(`#${vidPLAYER2}`).expand();
$w(`#${vidPLAYER2}`).show('fade');
}
//...more code
//...more code
//...more code
//...more code
});
});
So now you have a full setup for your "videoPlayer2’’ or however is the ID of your VIDEO-PLAYER-2.
You can expand your code at anytime, adding more functionality into your setup.
My assumtion might be, that you had a missing code-part, this is why your vide-player disappeared and did not come back. And maybe this is why you were thinking sometimes it is available, but once URL was missing it disappeared and did not come back!
Edit:
Make sure you adjust all your elementIDs like shown inside my code.
- for vide-player-2
- for dataset
You will find them inside the generated USER-INTERFACE.