Still trying to display ratings

Hi all!
I’m trying to display ratings on this dynamic page:
https://www.grahameschocolateguide.com/Chocolatiers/Acalli
I’ve been following these instructions:
https://support.wix.com/en/article/wix-code-tutorial-capturing-and-displaying-ratings
I’ve added the code and made the substitutions.
But it does not seem to be working.
What did I do wrong? : )
Thanks in advance.

export function ratingsInput1_change(event) {

// 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({
avgeRating: newAverageShort,
rSum: total + newRating,
noOfRatings: (count + 1)
});

// save the dataset fields to the collection
$w(‘#DynamicDataset’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}

Hi,
Have you changed the selector (e.g - “$w(’ #DynamicDataset ')”) to match the ID of the element in your site?

My apologies, I have a basic coding question: the coding area of my dynamic page already also has code for another feature (the Google map). How do I add this new code without affecting the other code? I find that simply by adding this code below the other code, it is causing the Google map to stop functioning. Thanks.

Hi,
The code above can’t make Google map stop functioning directly.
My guess is that you might have other errors that causing it.
Roi.

Well, what I find is that when I add the rating code below the Google map code, the Google map code stops working. I wonder if I’m supposed to separate the two sets of code in a certain way?

Please paste the url to your site and specify the name of the page. I’ll take a look.
Roi.

Thank you, much appreciated.

Right now, the only code I have added is for the Google map…because when I attempt to add the ratings code, the map stops working.

can you please add the rating code? let me know when you added it.

@roi-bendet Done.

@webguidesinternation
You have some syntax errors. (dynamic dataset name and one extra }); )
This is without errors:

$w.onReady(function () {
	$w("#dynamicDataset").onReady(() => {
		let currentItem = $w("#dynamicDataset").getCurrentItem();
		$w("#googleMaps1").location = {
			"latitude": currentItem.latitude,
			"longitude": currentItem.longitude,
			"description": currentItem.title,
		};
	});
});

export function ratingsInput1_change(event) {
	// 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({
		avgeRating: newAverageShort,
		rSum: total + newRating,
		noOfRatings: (count + 1)
	});

	// save the dataset fields to the collection
	$w('#dynamicDataset').save()
		.catch((err) => {
			console.log('could not save new rating');
		});
}

@roi-bendet Thank you so much! I’ll insert your version and give it a try. : )

Hmmm, the ratings function still does not seem to be working. I tried to leave ratings on a few of the chocolatiers with no apparent result. Suggestions welcome. : )

@roi-bendet Hi Roi…or anyone else. Again, I’ve pasted the code that Roi recommended above, but when I attempt leave a rating, it doesn’t seem to be recorded and displayed. Any suggestions most appreciated! Thank you.

Still seeking help on this issue…