Hi anyone, need some help. I am going to post my code, ive gotten to the point where the input rating is entered but doesnt save, not to the database and doesnt update on the display side. There are 3 different ratings elements on same page.
$w.onReady(()=> {
//TODO: write your page related code here…
});
export function ratingsInput1_change(event) {$w(“#paiduser”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#paiduser”).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(‘#overall1’).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(‘#paiduser’).setFieldValues({
‘averagerating’: newAverageShort,
‘sum’: total + newRating,
‘number’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#paiduser’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}
export function ethics1_change(event) {$w(“#paiduser”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#paiduser”).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(‘#ethics1’).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(‘#paiduser’).setFieldValues({
‘averagerating’: newAverageShort,
‘sum’: total + newRating,
‘number’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#paiduser’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
//Add your code for this event here:
}
export function volume1_change(event) {$w(“#paiduser”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#paiduser”).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(‘#volume1’).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(‘#paiduser’).setFieldValues({
‘averagerating’: newAverageShort,
‘sum’: total + newRating,
‘number’: (count + 1)
});
// save the dataset fields to the collection
$w(‘#paiduser’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}