I am using code below (staright out of wix) in a grouped ratings input. It works sometimes after repeating the input twice and does not other times? Can you help?
===
import wixLocation from ‘wix-location’;
import wixData from “wix-data”;
import { local } from ‘wix-storage’;
$w.onReady( function () {
//TODO: write your page related code here…
});
export function RatingsInput1_change(event) {
$w(’ #dynamicDataset ').onReady(() => { const currentItem = $w(" #dynamicDataset ").getCurrentItem();
const average = currentItem.alphaAvg;
const count = currentItem.alpha;
const total = currentItem.alphaTotal;
const newRating = $w(’ #ratingsInput1 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'alphaAvg': newAverageShort,
'alphaTotal': total + newRating,
'alpha': (count + 1)
});
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}
export function ratingsInput2_change(event) {
$w(" #dynamicDataset ").onReady(() => {
const currentItem = $w(" #dynamicDataset ").getCurrentItem();
const average = currentItem.bravoAvg;
const count = currentItem.bravo;
const total = currentItem.bravoTotal;
const newRating = $w(’ #ratingsInput2 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'bravoAvg': newAverageShort,
'bravoTotal': total + newRating,
'bravo': (count + 1)
});
// save the dataset fields to the collection
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}
export function ratingsInput3_change(event) {
$w(" #dynamicDataset “).onReady(() => {
// get the current item from the dataset
const currentItem = $w(” #dynamicDataset ").getCurrentItem();
const average = currentItem.charlieAvg;
const count = currentItem.charlie;
const total = currentItem.charlieTotal;
const newRating = $w(’ #ratingsInput3 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'charlieAvg': newAverageShort,
'charlieTotal': total + newRating,
'charlie': (count + 1)
});
// save the dataset fields to the collection
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}
export function ratingsInput4_change(event) {
$w(" #dynamicDataset ").onReady(() => {
const currentItem = $w(" #dynamicDataset ").getCurrentItem();
const average = currentItem.deltaAvg;
const count = currentItem.delta;
const total = currentItem.deltaTotal;
const newRating = $w(’ #ratingsInput4 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'deltaAvg': newAverageShort,
'deltaTotal': total + newRating,
'delta': (count + 1)
});
// save the dataset fields to the collection
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}
export function ratingsInput5_change(event) {
$w(’ #dynamicDataset ').onReady(() => {
const currentItem = $w(" #dynamicDataset ").getCurrentItem();
const average = currentItem.echoAvg;
const count = currentItem.echo;
const total = currentItem.echoTotal;
const newRating = $w(’ #ratingsInput5 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'echoAvg': newAverageShort,
'echoTotal': total + newRating,
'echo': (count + 1)
});
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}
export function ratingsInput6_change(event) {
$w(" #dynamicDataset ").onReady(() => {
const currentItem = $w(" #dynamicDataset ").getCurrentItem();
const average = currentItem.fancyAvg;
const count = currentItem.fancy;
const total = currentItem.fancyTotal;
const newRating = $w(’ #ratingsInput6 ').value;
const newAverageLong = (total + newRating) / (count + 1);
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').setFieldValues({
'fancyAvg': newAverageShort,
'fancyTotal': total + newRating,
'fancy': (count + 1)
});
$w(' [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~dynamicDataset) ').save()
. catch ((err) => {
console.log('could not save new rating');
});
});
}