Is there a way to hide any element that has an empty field on a dynamic page? In particular, I have a video that I’d like hidden when there is no URL in the field, but I would like to have it work on all fields. I am not a coder, so I will need detailed instructions.
- A dynamic-page always shows JUST-ONE-ITEM.
- This item is always loaded out of your DATABASE.
$w.onReady(()=>{
$w("#myDynamicDataset").onReady( () => {
let itemData = $w("#myDataset").getCurrentItem();
console.log(itemData);
console.log(itemData._owner);
console.log(itemData._id);
console.log(itemData.title);
});
});
Example: Let’s say you have 3 different TEXT-ELEMENTS on your page …
- Text-Element-1 - - → showing - - - > OWNER-ID.
- Text-element-2 - - → showing - - - > ITEM-ID.
- Text-element-3 - - → showing - - - > TITLE.
$w.onReady(()=>{
$w("#myDynamicDataset").onReady( () => {
let itemData = $w("#myDataset").getCurrentItem();
console.log(itemData);
console.log(itemData._owner);
console.log(itemData._id);
console.log(itemData.title);
$w('#myText-Element1').text = itemData._owner;
$w('#myText-Element2').text = itemData._id;
$w('#myText-Element3').text = itemData.title;
});
});
Still something missing right?
$w.onReady(()=>{
$w("#myDynamicDataset").onReady( () => {
let itemData = $w("#myDataset").getCurrentItem();
console.log(itemData);
console.log(itemData._owner);
console.log(itemData._id);
console.log(itemData.title);
if(itemData._owner) {
$w('#myText-Element1').show();
$w('#myText-Element1').text = itemData._owner;}
else {$w('#myText-Element1').hide();}
if(itemData._id) {
$w('#myText-Element2').show();
$w('#myText-Element2').text = itemData._id;}
else {$w('#myText-Element2').hide();}
if(itemData.title) {
$w('#myText-Element3').show();
$w('#myText-Element3').text = itemData.title;}
else {$w('#myText-Element3').hide();}
});
});
Thank you! Am I understanding correctly that I would have to add that if-else section of code for each element on the page?
Yes!
But if you have 1000-elements, you maybe should use a LOOP.
-for-loop
-each-loop