hi, I have a problem with the Rating Display. I created the function with the ratings and the average, everything works fine. The problem is: how do I get a user to vote only once? and not several times? Is there a check by IP address? or by email? do you have an idea how to do it? this is the code :
$w . onReady ( function () {
});
export function ratingsInput1_change ( event ) {
$w ( “#dynamicDataset” ). onReady (() => {
// get the current item from the dataset
const currentItem = $w ( “#dynamicDataset” ). 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 ( ‘#dynamicDataset’ ). setFieldValues ({
‘avg’ : newAverageShort ,
‘totalRatings’ : total + newRating ,
‘numRatings’ : ( count + 1 )
});
// save the dataset fields to the collection
$w ( ‘#dynamicDataset’ ). save ()
. catch (( err ) => {
console . log ( ‘could not save new rating’ );
});
});
}
Thanks