Good day wix community! I am a newcomer to WIX and this community so I am not really sure how this works, nonetheless, I have a coding issue and require some assistance.
I have successful added display ratings to my repeaters and linked these (display ratings) up to their respective data collection fields. I have also been able to add a user dropdown function and was able to copy and paste the wix code to change and update a single display rating within the repeater.
However, I am trying to replicate this rule for each individual item in the repeater but was unsuccessful in that area. Can someone please assist?
Below is the wix code I current use:
export function dropdown1_change(event) {
// get the current item from the dataset
const currentItem = $w(“#dataset1”).getCurrentItem();
// get the current average rating and number of ratings
const average = currentItem.ratingValue;
const count = currentItem.ratingCount;
// get the new rating from the dropdown and make it a number
const newRating = Number($w(‘#dropdown1’).value);
// calculate the new average rating based on the current average and count
const newAverage = ((average * count) + newRating) / (count + 1);
// save new average rating and total ratings to the collection
$w(‘#dataset1’).setFieldValues( {
‘ratingValue’: newAverage,
‘ratingCount’: count + 1
} );
$w(‘#dataset1’).save()
. catch ( (err) => {
console.log(‘could not save new rating’);
} );
// disable the dropdown
$w(‘#dropdown1’).disable();
}
Many thanks and best regards
Dwaine