Create a download button for uploaded documents

Hi, I’m new at coding, so please excuse me if this is a silly question or if what I’m asking isn’t possible.

I set up my page as Code Queen Nayeli did. Thank you - it all works fine! The idea is that the member fills out a form and submits it, then on their ‘submission history’ page it updates with a summary of what the client has submitted. This works fine and updates only what the logged-in member has submitted.

Now I am struggling with the buttons because I’m using a repeater on the member’s page. I’ve liked a ‘Download Estimate’ button on the repeater to the dataset I’m using, and the document downloads fine. But now I would like the download button to show only when a document is available in the database. I’ve tried the code offered here but it doesn’t work. I’ve looked at working with repeaters and I’m confused. Do I have to use $item? Or is what I’m after not possible?

Any help would be greatly appreciated!

Thank you in advance

Hi :slight_smile:

Thanks for watching my videos. So I think you want to hide download button on a repeater if the field is empty (no document)? If yes, try something like this:

My code has a lot going on but it should give you a hint to what you should write in your code …

(In my code popupButton opens a lightbox … and soloPageButton is disabled if no word is found in the database, preventing them from clicking.)

:wink:

import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady(function () {
 $w('#repeater2').onItemReady(($item , itemData , i ) => {
 let itemEmpty = $item('#companyDataset').getCurrentItem();
 let soloEmpty = itemEmpty.soloPage;
 
    $item('#popupButton').onClick(() => {
 let item = $item('#companyDataset').getCurrentItem();
        wixWindow.openLightbox('Popup', item)
     });
 });

 $w("#repeater2").onItemReady( ($w, itemData, index) => {
 let word = itemData.soloPage;

 if ( word === undefined) {
        $w("#soloPageButton").disable();
    } else if ( word !== undefined) {
        $w("#soloPageButton").enable();
    } 
    });
});

Hi Code Queen Nayeli

Thank you so much for this! I changed the necessary things, resolved an error I made and now it all works exactly how I wanted it to!

Thank you! You’re a gem!

P.s. Your videos and advice always get me through!

@alexfors Hey Alexander,
What do you mean by “test” fields? Also, did you double check your collection permissions?

@jeff-wix Not sure what I meant, think I meant “text” fields haha… but I got It to work, sorry! :slight_smile:

Hello,

How to get the download link using the code?

let obj = $w('#dataset').getCurrentItem();
let objLink = obj["fileLink"];

console.log(objLink) // return undefined

Logging the item data to the console returns undefined for the “Document” type, and returns the expected value on other fields.

Hi, I tried this but the button remained disabled. I then tried to set the dataset to read and write and finally the button gets enabled.

But once I click on the button it doesn’t download the item on it.

What am I missing?