top of page

Forum Posts

Chanel
Oct 30, 2018
In Coding with Velo
I carefully copied and pasted the code provided in the Wix Code Tutorial ("Capturing and Displaying Ratings") to my page, then edited it to reflect my personal field keys, etc, but not everything is working and I don't know where I went wrong. The review input elements are coded to be sent to my Venues_Reviews dataset upon clicking '#button2'. Almost everything works (Venue Name, Reviewer's Name, Wedding Date, Rating & Comments) EXCEPT the part where it's supposed to input the average rating (field key: averageRating), number of ratings (field key: totalReviews) and total ratings (field key: totalRatings). After doing a test submission, these fields are left empty. I've pasted my code below, can anyone tell me if there's an error somewhere? export function button2_click(event) {   $w("#dataset1").onReady(() => { // get the current item from the dataset const currentItem = $w("#dataset1").getCurrentItem(); // get the current average rating, number of ratings, and //total ratings for the current dataset item const average = currentItem.averageRating; const count = currentItem.totalReviews; 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('#dataset1').setFieldValues({ 'venueName': $w('#input2').value, 'reviewersName': $w("#input1").value, 'weddingDate': $w("#datePicker1").value, 'rating': $w("#ratingsInput1").value, 'comments': $w("#textBox1").value, 'averageRating': newAverageShort, 'totalReviews': total + newRating, 'totalRatings': (count + 1)   }); // save the dataset fields to the collection   $w('#dataset1').save()   .catch((err) => {   console.log('could not save new rating');   });   }); }
0
12
774

Chanel

More actions
bottom of page