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.
I have tried for nearly two weeks now without any success. One of your experts had a look direcly on my page but could not solve it either because something is seriously wrong with this example. Why shall you not connect the rating input element to the dataset? If you don´t do that nothing happends at all and if you connect it to Avg still nothing happends. You have to connect it to NumRatings but then the stats doubles or triples up when you click on a star. Extremely frustrating so I nearly go mad with this đ Please create an instruction video for beginners because this is extremely hard.
This is a very confusing instruction because it doesn´t work and on another page the same author has written that you shall connect the damn input element!
In your page
Set your dataset's mode to "Read and Write." This will let your visitors update information in the collection.
Add the following elements:
A Ratings Display element connected to the new Number fields in your collection.
A Ratings Input element your visitors can use to pick a rating for the item. You can use the default setting for the ratings, or define your own. Do not connect it to the dataset.
Source:
https://support.wix.com/en/article/velo-tutorial-capturing-and-displaying-ratings
Source:
https://support.wix.com/en/article/ratings-input
Hello Russian-dima, I have followed your formula step by step and the same thing happens to me. Apparently this function cannot be applied on a repeater. When I enter a rating it only changes the value of "numRatings" in the database, but "avg" and "totalRatings" are not modified in Live Data. Today I will make a last test although I have already tried everything.
Thank you very much for the help, I will try it in a moment and I will tell you how it turned out
This one should work...
$w.onReady(function () { }); export function ratingsInput1_change(event) { $w("#dataset1").onReady(() => { const currentItem = $w("#dataset1").getCurrentItem(); const average = currentItem.avg; const count = currentItem.numRatings; const total = currentItem.totalRatings; const newRating = $w('#ratingsInput1').value; const newAverageLong = (total + newRating) / (count +1); const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1); $w('#dataset1').setFieldValues({ 'avg': newAverageShort, 'totalRatings': total + newRating, 'numRatings': (count + 1) }); $w('#dataset1').save() console.log("Rating completed.") }); }
All you have to do is...
1) Copy&Paste this code and replace your own with this one.
2) Creating a DATABASE (called as you want) and set up 3 REFERENCE-FIELDS (Avg / TotalRatings / NumRatings).
All three fields set to NUMBER (in this example).
Now the RATING-INPUT should be ready.
Then you create an RATING-OUTPUT, through connecting a dataset with collection and the dataset (in this example dataset1) with OUTPUT-RATING.
Hello
Yes, I have added 3 numeric fields which I leave empty. The privacy settings I have also reviewed. The connector configuration was read / write
Hello Sebastian,
did you configure your database right?