Hi.
I want to show the file names of files stored in data collections in repeaters.
The files are document type files ( meaning that cell field type is set to Documents)
I want to show the file names of each file in buttons placed in a repeater.
How can this be done.?
I’m assuming that it can be done with a code like below,
but I cannot seem to get the middle ”FILE1” part right.
*The columns which hold the document files (.doc, .ppt) in the data collection is named file “FILE1”
my current code:
$w("#dataset1").onReady( () => {
$w("#repeater1").forEachItem( ($w) => {
var buttonname = item.FILE1;
$w("#button2").label = (buttonname);
});
});
Below is a simple sample image of what I want to do.
I want the file to download when you click the button.
A complete top to bottom code sample would be appreciated.
Thanks.
Ken
Hi Kenny,
Here are some suggestion for you.
//...
$w("#dataset1").onReady( () => {
//If you want to use $w("#repeater").forEachItem() >
//You need to tell repeater where to get data..
//In below, repeater will get data from dataset
$w("#repeater1").data = $w("#dataset").getCurrentItem();
$w("#repeater1").forEachItem( ($w, itemData, index) => {
//Your field name may not be FILE1 because it may start from small letter
//I think it may fILE1 more than FILE1
$w("#button2").label = item.fILE1;
//button.label will affect the name only.
//If you need to add a link to it...
$w("#button2").link = item.fILE1url;
//"_blank" will open a new window | "_self" will open in current window
$w("#button2").target = "_blank";
});
});
Special remark:
① If you add code to a button, all function without code may disappear
② You only need to connect your repeater to dataset, no need to connect items in each single card.
③ Don’t put your download link inside button onClick()
Have a good day😊
Heson
2 Likes
Heson
Thank you very much for responding. Really appreciate your help.
But I unfortunately I still can not get it to work.
When I put the code in the page
there’s a red line under “item” and it says
“item” is not defined. (The button link part of code was commented out at this point to narrow down the cause)
I made a new column named “file1” (not “FILE1”) and tried this too but
It did not work either.
The problem at the simplest form is this:
If I make a text element on a blank page (like heading 1 ),
and connect it to a data collection,
I can connect it to a Text type field
but I can’t connect it to a Document type field, because it’s greyed out from the beginning. (as shown below)
the data collection looks like this. A Document type field like below.
How do you get the file names of a document file stored in a Document type field or cell to show on a page?
Thank you and regards.
Ken
Hi again,
there are some mistake in it.
You can replace below to line15.
$w("#repeater1").onItemReady( ($w, itemData, index) => {
Thank you very much for responding again.
For some reason, I still cannot get it to work.
It still has the same, ‘item’ is not defined caution appearing.
But really thank you.
Will keep trying.
I am thinking of re-posting this question in a more simpler state.
Thank you and regards.
Ken
Hi,
item is not defined. Change it to itemData.
Roi.
1 Like
Roi
Many many thanks. It worked.
Finally, I’m able to pull out the file name from the database.
Thank you very much to all whom responded.
May be I should post this as a new question, but
if the original file’s, filename was “Flyer01.pdf” , the file name I get is like below.
WIX seems to add it’s own file ID (or name) in front of the original filename.
wix:document://v1/d49556_2c6f0bxxxxxxx95cdcaa154f777521a.pdf/Flyer01.pdf
I will have to think of a way to extract only the original filename from this.
Anybody from WIX? is there a quick way to do this?
Thank you and Regards
Ken
Hi Kenny,
Please post it as a new question.
Roi.