I’m using the code below on dynamic item page to collect rating but TypeError show up every time i rate. There is not problem with this code in editor, only in live site. Also, when i am try to check with the next dynamic page, “Failed to load initial data” appear in console, but the page loaded nicely except the rating data. Do anyone know how to debug or solve this problem?
export function ratingsInput1_click(event) {
$w(“#dataset1”).onReady(() => {
const currentItem = $w(“#dataset1”).getCurrentItem();
const average = currentItem.avg;
const count = currentItem.numRatings;
const total = currentItem.totalRatings;
const newRating = $w(‘#ratingsInput1’).value;
const newAverageLong = (total + newRating) / (count +1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(‘#dataset1’).setFieldValues({
‘avg’: newAverageShort,
‘totalRatings’: total + newRating,
‘numRatings’: (count + 1)
});
$w(‘#dataset1’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}