Sorry if that title is confusing. Here’s what I’m trying to do – Make an attendance sign-in page for a youth group. I have a collection with all of the youth information. I have another collection with dates for the attendance tracker along with a field for the referenced items of youth.
I have it set up so on a dynamic page (showing items from the dates collection), I have a repeater with all of the youth in it and a check-in button. I want it so when that button is clicked, it adds the reference of the student’s name into the collection of the dates. Here’s the code I have so far…
import wixData from ‘wix-data’;
$w.onReady( async function () {
});
let debounceTimer;
export function MakeRepeater() {
$w(“#repeater1”).forEachItem( ($item, itemData, index) => {
$item(‘#button1’).onClick( (event) => {
$item(‘#button1’).label = “Checked In”;
console.log(“click.”);
let nameID = itemData._id;
wixData.insertReference("YouthAttendance", "Attendance", "00001", nameID)
.then( () => {
console.log("Reference inserted");
} )
. **catch** ( (error) => {
console.log(error);
} );
});
});
}
export function searchBar_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchBar’).value);
},200);
}
let lastFilterTitle
function filter(title) {
if (lastFilterTitle!== title) {
const byFirstName = wixData.filter().contains(‘studentFirstName’, title);
const byLastName = wixData.filter().contains(‘studentLastName’, title);
$w("#youthGroup").setFilter(byFirstName.or(byLastName));
lastFilterTitle = title;
}
}
export function repeater1_itemReady($item, itemData, index) {
MakeRepeater();
}
I know that the “Insert” function isn’t working but it’s mostly because I just don’t really understand the reference documentation on it. I think I’m getting the ID correctly from the item in the youth collection, just not sure how to enter it into the item from the attendance collection.