I am trying to implement a rating system for items for which are in a repeater.
To achieve this I have followed this tutorial step by step: https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings
The problem is that I can't get it to work for me. When I run it in preview and try to rate an item this is what it shows me:
![](https://static.wixstatic.com/media/a27d24_5b71b7afb7ce45669e104fa32872ae0c~mv2.png/v1/fill/w_980,h_417,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_5b71b7afb7ce45669e104fa32872ae0c~mv2.png)
I don't know what mistake I'm making, I can't save my users' ratings. Please, some expert that can guide me? This is the code I am using:
$w.onReady(function () { //TODO: write your page related code here... }); 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({ 'rating': newAverageShort, 'totalValoraciones': total + newRating, 'numeroValoraciones': (count + 1) }); // save the dataset fields to the collection $w('#dataset1').save() .catch((err) => { console.log('could not save new rating'); }); }); }
This is the URL: https://www.app-onlinebox.com/desafios-comunidad
Thanks in advance.
See this Ratings by User Example.