can you put a rating input & display into a repeater

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

Make sure that these are your field keys.
const average = currentItem.avg;
const count = currentItem.numRatings;
const total = currentItem.totalRatings;

Is ‘avg’, ‘numRatings’ and ‘totalRatings’ your actual field key names in your dataset?
For that to be the case your dataset field names should be ‘Avg’, NumRatings’ and TotalRatings’.

Also, check that your dataset is actually called ‘#dataset1’ and your dropdown element is called ‘#ratingsInput’.

If you have done everything as stated on this tutorial then as said on it at number 3 of testing the code…
Preview your page and test out the Ratings Input element. Watch how the ratings display element updates when you add a rating.

However, if you are still not getting anywhere and still having the Nan/null error message appear, then simply add a false rating number into your dataset in your sandbox version and test it again.

Nan basically stands for not a number, so as your dataset for the ratings is currently empty it is seeing null, zero or 0/0 is undefined as a number hence the NaN error message.

You will probably have to sync the sandbox to live for the website to work with the live dataset if that does fix it.

As for the repeater, you might need to use onItemReady as Yisrael describes in this old forum post here.
https://www.wix.com/corvid/forum/community-discussion/displaying-rating-from-wix-code-example-in-other-page
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady

Also, if you are doing it through Wix Stores, then there is already a tutorial for that.
https://support.wix.com/en/article/corvid-adding-ratings-and-reviews-to-a-wix-stores-site

Finally, Yisrael (Wix Admin) had mentioned this on a previous post too, so worth a look for you.

Here is a very simple example of the RatingsInput component:
View the Live demo in a browser page
Open the Example template in the Wix Editor
Note : The RatingsInput component is on the RECIPE Lightbox page.

Hi, Thanks for your reply. all the fields are connected to the correct fields and working perfect. adding up the average and displaying the number of reviews. that is when they are on a page. when i add them to a repeater on the page is when it stops working.

I’m new on Wix.
How you can open window with specific data from repeater?
In your example when Click on repeater, you open the specific recipe on new window

Hello Saulo,

when you wanna get some answers, you should better open a new own post, with own issue/problem. You can reffer to this post he, to connect it to your own post.

And remember, that this forum here is CODE-RELATED.

If you work without CODE, so the Wix-Support will be the right contact-person for you…

You can fin all important URLs here in this little collection…
https://russian-dima.wixsite.com/meinewebsite/blank-5