Sorry if this has been posted and fixed elsewhere. i’m hoping this is a simple fix as i am very limited when it comes to code
i have a star rating system on my site to work out the number and average or ratings submitted. all of that works perfect. as soon as i add them to my repeater it stops working.
i have a list of items on a page displayed on a repeater and connected to a collection. i want them to be rated by star individually. when i add them to the repeater this is the error message i get. also the recorded numbers from the average and submitted ratings disappears.
Wix code SDK error: The rating parameter that is passed to the rating method cannot be set to the value NaN. It must be of type number.Wix code
SDK Warning: The rating parameter that is passed to the rating method cannot be set to null or undefined.
this is the code i currently have
import wixData from ‘wix-data’;
export function ratingsInput1_change(event) {
$w(“#dataset1”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#dataset1”).getCurrentItem();
// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.avg;
const count = currentItem.numRatings;
const total = currentItem.totalRatings;
// 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(‘#dataset1’).setFieldValues({
‘avg’: newAverageShort,
‘totalRatings’: total + newRating,
‘numRatings’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#dataset1’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}
thank you to anyone who can help