Hi! I have an order date in the collection, created an expiration date using hooks, and was able to display them on the repeater.
However, the expiration date on all the repeaters only display the date based on the latest date I submitted. I guess the hook is alright but there must be something wrong with the code on the page.
The hook I use:
export function warrantyinfo_afterQuery(item) {
item.expDate = setExpDate(item.orderDate);
return item;
function setExpDate(orderDate) {
var originalDate = new Date(orderDate);
var date = new Date(originalDate);
// set expiration 2 year
date.setDate(date.getDate() + 730);
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const day = date.getDate().toString();
const longMonth = monthNames[date.getMonth()];
const year = date.getFullYear().toString();
var expDate = longMonth + "/" + day + "/" + year;
return expDate.toString();
}
}
The page code:
$w.onReady(function () {
$w("#warrantyinfodisplay").forEachItem( ($w) => {
$w("#warrantyinforead").onReady(() => {
populateCalculatedFields();
});
});
})
function populateCalculatedFields() {
const Item = $w("#warrantyinforead").getCurrentItem();
$w("#expirationdate").text = Item.expDate;
}
On the repeater:
The expiration date is wrong in the second repeater, which should be April/1/2022 instead. What should I do?
P.S. I am a total rookie to writing codes, thanks to these posts I am able to build my site step by step.
Thank you in advance!