Dynamic ratings in Repeater

hi all, have been trying to create a dynamic rating system within a repeater following: https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings

While this works using the example and a normal page, as soon as I place my ratingsInput field within a repeater it seems like it returns a null value (and resets my data fields (all except the user count), the reason for me needing this is that I’m creating a ratings service for businesses.

Users will be given four parameters to rate the business on, Staff, Environment, Location and Price and need them to weigh in to the total general average (my ratings display).

Since im looking to add hundreds of businesses to the dataset I really need to place this within some kind of repeater that is then filterable.

Any input on how to do this would be appreciated.

Code used is bellow, as stated this works as long as I don’t place the #ratingsInput1 within a repeater.

$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.averageRating;
 const count = currentItem.submittedNumber;
 const total = currentItem.sumOfRating;

 // 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({
 'averageRating': newAverageShort,
 'sumOfRating': total + newRating,
 'submittedNumber': (count + 1)
  });
 
 // save the dataset fields to the collection
  $w('#dataset1').save()
   .catch((err) => {
    console.log('could not save new rating');
   });
 });
 // Add your code for this event here: 
}

Thank you for any input :slight_smile:

Best Regards
Max

Hi Max, are you just trying to display the overall rating for each item? or to let the user enter a variety of ratings for each item?

This might help either way
https://www.wix.com/corvid/example/product-reviews

Hi Stephen, in an ideal world, as a user adds a rating for one specific area (staff for example) it would automatically update the general average ranking. Currently the input returns a 0 to the DB, seems this might be that it doesn’t recognise what value to send to where

Have you seen the example above? I think it may help with some tweaking for your needs.