I have a site that displays a text, image and a button for downloading a pdf , if there is no pdf on my data set I would love for the entire strip that contains the text, image and button to hide away, simple not load or show on the website.
Here is a screenshot of the area I would like to hide in case there is no pdf on my data set items,
Is there a code that can hide an entire strip and its contents based on an empty field on from my dataset, the empty filed would be a file type column.
Hi there I do something similar on my site. Below is the working code that I use to accomplish this, just swap out the element IDs for your own and change “yourFieldKey” to the field key of the database item you want to find.
$w.onReady(function () {
$w("#yourDataset").onReady(() => {
var item = $w("#yourDataset").getCurrentItem();
if (currentItem.yourFieldKey) {
// If there IS a value in the database field
$w("#yourElement").expand();
} else {
// If there is NOT a value in the database field
$w("#yourElement").collapse();
}
});
});
There are many many forum posts that deal with this exact question, you can check out a few of them here: