Should be a simple two questions as In you cant do that or follow this link hopefully?
I tried dragging a rating to a repeater and it appears only once on the first repeater. This seems to happen after I add some code and a user rating input element.
So the the second problem is the user input element. It is only working for the first repeater element, do I need additional code here to make it work for all repeaters? btw the database is just adding or summing the avg input. One thing that I dont understand is why did the coder change the default Average field from average to avg? This is nutty to me.
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
$w.onReady( function () {
//TODO: write your page related code here…
});
export function ratingsInput1_change(event) {
//Add your code for this event here:
$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’);
});
});
}