I have a collection list showing one row for each of a month. I add a collection list into the page, and when selecting the collection source, it shows the 30 rows, one for each day.
Now, I have the day of the month and I have a button. With a custom code embedded in the collection item, I am trying to read data specific to that collection item into a JavaScript (to pass the data to a pop-up modal screen).
The problem seems to be that the button is repeated for each collection and this is why it has one ID. So if I click on any of them buttons, I will get the same data of the very first row, not of the row I clicked its button.
A visit to the following links might explain the issue. I am not sure if there is something I can do, or it is currently not addressed in CMS collection features.
From the menu bar, click “Ramadan”, then “Iftar Service Schedule”.
Adding a button for each row is not the problem. What I am trying to do, is getting the data from the row. For instance, if I click on the button on the third row, I need pass the number appearing in the “ID: Day” text field (which is the number appearing in green in each row) to the “BookDay” in the modal pop-up (the first Modal Rapper).
I added an embed code item and wrote the code for you to check.
It works fine for the first row. But it doesn’t for any other row.
Again - by code its simple to solve this (to get the number “3”) when you click on 3 - but what is the end result? (You put this var inside function, view or and other trick)
This code store the number of the button by data-day. So on webflow use this idea:
Inside your modal add text-element with id of “status”
Publish. Than by js every click will change this text inside #status (click on book1 to 1 and so on).
before body – copy—paste code
<script>
var dataElement = $("button.iftar-button");
var number = "";
$(dataElement).each(function () {
var $this = $(this);
$this.on("click", function () {
number = $(this).data('day');
$('#status').html(number);
});
});
</script>
What is “book”? Again you should bind the data. You won’t get always 30 if you bind the click to this element button.iftar-button (Every click the var change).
In your example you use “day of month” (same value) for every click.