I am getting a warning followed by an error when testing the ratings element. The error occurs even when I add a starter number in the collection. Can anyone please help?
Error:
“Wix Code SDK Warning: The rating parameter that is passed to the rating method cannot be set to null or undefined. It must be an integer.”
Used code:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here…
});
export function dropdown1_change(event, $w) {
// get the current item from the dataset
const currentItem = $w(“#dataset1”).getCurrentItem();
// get the current average rating and number of ratings
const average = currentItem.averageRating;
const count = currentItem.numRatings;
// get the new rating from the dropdown and make it a number
const newRating = Number($w(‘#dropdown1’).value);
// calculate the new average rating based on the current average and count
const newAverage = ((average * count) + newRating) / (count + 1);
// save new average rating and total ratings to the collection
$w(‘#dataset1’).setFieldValues( {
‘impressAvg’: newAverage,
‘impress’: count + 1
} );
$w(‘#dataset1’).save()
.catch( (err) => {
console.log(‘could not save new rating’);
} );
// disable the dropdown
$w(‘#dropdown1’).disable();
//Add your code for this event here:
}