@yisrael-wix This is the code I use and I have created the fields heterosexRating, heterosexNumber and heterosexTotal because I´m making a sex site
I have been able to make the rating display element show the correct rating but when I go back to the page and click for a new rating the total rating is gone. Very frustrating because I have a field for that wich also are connected with the dataset:
export function ratingsInput1_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
$w(“#dataset2”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#dataset2”).getCurrentItem();
// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.heterosexRating;
const count = currentItem.heterosexNumber;
const total = currentItem.heterosexTotal;
// get the new rating from the ratings input
const newRating = $w(‘#ratingsInput1’).value;
// calculate the new average rating based on the current
//average and count
const newAverageLong = (total + newRating) / (count +1);
// Round the average rating to 1 decimal point
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
// set the dataset fields to the new average, total
// ratings, and number of ratings
$w(‘#dataset2’).setFieldValues({
‘heterosexRating’: newAverageShort,
‘heterosexTotal’: total + newRating,
‘heterosexNumber’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#dataset2’).save()
.catch((err) => {
console.log(‘could not save new rating’);
});
});
// Add your code for this event here:
}