I created classic input with five stars, and I connected it to the database column, counting the number of reviews, the value of each review, and the average. Here is the code. It works but only after the second review. The first review is problematic - it does not display. I think that the reason is that when there is no value in the database, it can’t count with it, but I do not know how to fix it. Does someone have an idea, please?
export function button51_click ( event ) {
$w ( “#dataset1” ). onReady (() => {
const currentItem = $w ( “#dataset1” ). getCurrentItem ();
const average = currentItem . hoaverage ;
const count = currentItem . hocount ;
const total = currentItem . hototal ;
const newRating = $w ( ‘#ratingsInput12’ ). value ;
const newAverageLong = ( total + newRating ) / ( count + 1 );
$w ( ‘#dataset1’ ). setFieldValues ({
‘hoaverage’ : newAverageLong ,
‘hototal’ : total + newRating ,
‘hocount’ : ( count + 1 )
});
$w ( ‘#dataset1’ ). save ()
. catch (( err ) => {
console . log ( ‘could not save new rating’ );
});
});
$w ( ‘#columnStrip23’ ). expand ()
}