Hide a box when database is empty

I have 2 boxes one on top of the other in a container.
I’d like the top box to disappear when my Database is empty and the box below goes up … can someone help me with the code, I struggle …

Just do what it says in the Forum Guidelines and use the search function in this forum and you would have found an old forum post on this…
https://www.wix.com/corvid/forum/community-discussion/hide-a-repeater-if-dataset-is-empty
https://www.wix.com/corvid/forum/community-discussion/hide-an-empty-field
https://www.wix.com/corvid/forum/community-discussion/hide-image-text-on-dynamic-page-if-there-is-non-in-database

Thanks… I saw these old post but it disn’t work as well…

So, I tried this… but know the box is hidden even if the item is full…
Someone has an idea?

$w.onReady(() => {
$w(“#dynamicDatasetFICTION”).onReady(() => {
const item = $w(“#dynamicDatasetFICTION”).getCurrentItem();
if (!item.venteDistribution) {
$w(“#boxDISTRIBUTEUR”).collapse();
}
});
});

https://www.wix.com/corvid/forum/community-discussion/how-to-hide-elements-based-off-other-empty-elements

Thanks GOS for the link but the code doesn’t work anymore… I’m desperate, I worked on it for 6 hours… and still doesn’t work… The last code hide the element even if the fields is full…

Sorry GOS, but I spent the night on that code and nothing work, I don’t write code for a very long time and I don’t see what I’m doing wrong…
Some help please? This is the only code I have to write…

This is the las trials…






$w.onReady(() => {
$w("#dynamicDatasetFICTION").onReady(() => {
// Gets the current item properties and stores them in a variable called item
const item = $w("#dynamicDatasetFICTION").getCurrentItem();
// Checks if the current item has a value in the "venteDistribution" field
if (!item.venteDistribution) {
// Collapses the box if there is no value for "venteDistribution"
$w("#boxDISTRIBUTEUR").collapse();
} else {
console.log("Expand");
$w("#boxDISTRIBUTEUR").expand();
}
});
});

#dynamicDatasetFICTION

Is this the actual ID name of your dataset on your page?

Hover over the dataset icon on your page to view the ID name on the top left.

Or open the properties panel for this dataset and you will see the ID name at the top.

Plus, this line is not getting a field as it is getting all items.
const item = $w(“#dynamicDatasetFICTION”).getCurrentItem();
// Checks if the current item has a value in the “venteDistribution” field

https://www.wix.com/corvid/reference/wix-dataset.DynamicDataset.html#getCurrentItem

To get a field only then change your code to suit.
$w(“#dataset1”).getCurrentItem().field;

Just remember to change field to the field that you want to use.

Thanks a lot GOS!
here you have what I see as name… Do you think I’m wrong with it? I’m really sorry to be so lame…

So, the news code, thanks to you works…
But… there is a but… the element is hiding everywhere on the dynamic page even if the field has data… I think I work with the good ID name… but I do something wrong but I don’t know what… it’s frustrating…

$w.onReady(() => {
$w(“#dynamicDatasetFICTION”).onReady(() => {
const item = $w(“#dynamicDatasetFICTION”).getCurrentItem().venteDistribution;
if (!item.venteDistribution) {
$w(“#boxDISTRIBUTEUR”).collapse();
} else {
console.log(“Expand”);
$w(“#boxDISTRIBUTEUR”).expand();
}
});
});

Did you originally use the code from here.
https://support.wix.com/en/article/corvid-tutorial-hiding-a-video-player-when-there-is-no-video-to-play

As it should work if done correctly.

Change the dataset ID to yours and the field to yours and your element to collapse and just use the collapse function as you won’t need the else command.

@givemeawhisky I did it 10 times yesterday and this morning… it doesn’t work… I don’t understand why …

Dear @GOS, I do it again with that code :
$w.onReady(() => {
$w(“#dynamicDatasetFICTION”).onReady(() => {
const item = $w(“#dynamicDatasetFICTION”).getCurrentItem();
if (!item.venteDistribution) {
$w(“#boxDISTRIBUTEUR”).collapse();
} }); });

There is an empty box on my page…

So I do this :
$w.onReady(() => { $w(“#dynamicDatasetFICTION”).onReady(() => {
const item = $w(" #dynamicDatasetFICTION “).getCurrentItem().venteDistribution;
if (!item.venteDistribution) { $w(”#boxDISTRIBUTEUR").collapse();
} }); });

And the box disappeared even if I’ve got data…

Do you see what I’m doing wrong… ?

Me gain,
since there it is “Rich Text” on my database field “venteDistribution”… maybe there is something to do directly on the database? I try everything I can :slight_smile: