Enable/disable an item in UI when using a repeater and data set

I am creating a News page, using a Repeater and data set and have eight items displayed. There is only one of those items that needs a download button/icon for a PDF white paper. Does anyone know how I can have the download Icon show on only the one news item with the PDF data associated to it, and not the other seven that don’t have the associated pdf?


Many Thanks!

Make sure your DEV MODE is turned on.
The following code will hide a button if there is no data applied to it for an item.

$w.onReady(() => {
    $w("#dynamicDataset").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#dynamicDataset").getCurrentItem();
 // Checks if the current item has a value in the "button" field
 if (!item.button) {
 // Collapses the button if there is no value for "button"
            $w("#button123").collapse();
 }
 });
}); 
  • Change the ID for the “#dynamicDataset” to match the ID of your dataset.

  • Change the ID for the “if (!item.button)” to match the name of the dataset item

  • Change the ID for “#button123” to match the ID of your button.

Thank you, so much!
I will give this a try, I’m a designer, so I could very well break something. :smile:

Hi iamteejay,
I have been super busy, but finally tried to use the code you gave me and I’m getting an error, unfortunately the debug console is no longer displaying it, instead opting to spam “To debug this code, open lzhdo.js in Developer Tools.” (which I can’t find). The code you sent isn’t picking up if the Dataset has a .pdf in it, I tried changing “if (!item.button)” to the below, and several others (item.document & .pdf) but I’ve not had any success. Below I’ve included a picture of what the dataset looks like, along with the modifications to the code.

Let me investigate latter tonight. Have you tested it in published mode? There are many things that don’t perform in the PREVIEW mode. Can share your page, please?

The site hasn’t been published yet, how do I share a page?

So you have only save the site, never published? Top right next to the save button click Publish. Then copy the url and share that?

I’m the designer, my client owns the site… It’s not ready to publish. What kind of info are you looking for? Can I get that for you?

@mottdesign In your code, I notice that you have

// Checks if the current item has a value in the “button” field
if ( ! item .pdfDownload0){

Yet, your screen shot of the content manage for an item show your PDF field, just saying “pdf”. Did you change the property to “pdfDownlload0”? If you didn’t then your IF line should be

// Checks if the current item has a value in the “pdf” field
if ( ! item .pdf){


Are you not testing the site LIVE?

Normally new sites don’t have the domain name associated with it, and have the https://iamteejay.editorx.io/ name-of-site

OR

If you are working with a live site, you can keep the new stuff off the navigation and hide the pages from search engines.

IF you haven’t viewed the site live, then it will be hard to know if the code works, as it doesn’t work in PREVIEW MODE.

Alternatively.

@teejay I’m going to have to check with my client before publishing it, thank you for your help though.