top of page

Forum Comments

[New Elements] Introducing Ratings
In News & Announcements
Pagination can't be used with a filtered repeater data set?
In Coding with Velo
Example: RatingsInput and RatingsDisplay
In Tips, Tutorials, Examples
Chanel
Mar 24, 2019
Can you please share the code you used to calculate the average? I'm trying desperately to follow the tutorial on Wix about capturing and displaying ratings, but I want to be able to also show things like company name, reviewer name, comments, etc. along with the rating AND average rating + total number of ratings. I tried to careful modify the code, but it's not working. This is the code I used: import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady( () => { ////// I added this extra bit of code to make sure visitors are logged in before reviewing if(wixUsers.currentUser.loggedIn) { $w("#text141").text = "Share Your Experience";     $w("#button2").show() } else { $w("#text141").text = "Please Login First"; $w("#button2").hide(); } } ); 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.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('#dataset1').setFieldValues({ 'venueName': $w('#input2').value, 'reviewersName': $w("#input1").value, 'weddingDate': $w("#datePicker1").value, 'rating': $w("#ratingsInput1").value, 'comments': $w("#textBox1").value, 'avg': newAverageShort, 'numRatings': total + newRating, 'totalRatings': (count + 1)   }); ////// I'd also like visitors to be able to upload a photo with their review, but haven't been successful yet // save the dataset fields to the collection   $w('#dataset1').save()   .catch((err) => {   console.log('ERROR');   });   }); } $w.onReady( function () { ///// this bit of code is to disable the review submit button after review is sent $w("#button2").onClick( (event) => { let $item = $w.at(event.context);    $item("#button2").label = "SENT!";   $item("#button2").style.backgroundColor = "#D1D4E0"; $item("#button2").disable()         .then( () => {           console.log("Button now disabled");         }); } ); } );
0
0
[New Elements] Introducing Ratings
In News & Announcements
retrieve the items data that is clicked in a repeater
In Coding with Velo
Chanel
Oct 27, 2018
Hi @Yisrael (Wix) Thank you for sharing the above code for chajj, I was able to apply a part of it for a similar task I am trying on my website. I feel like I'm ALMOST able to accomplish what I hope to do, I just need help with a couple more things and am very much hoping you can help me :) Here is my scenario: I have a regular page where I've built a custom form and a repeater to display dynamic content from my "Venues" database. The custom form button has been placed within the repeater. The custom form is meant to act as a "universal message" that can be sent to every venue a site visitor chooses to contact (through an on click event). I've been successful in connecting my custom form elements to my "Form" database wherein I can click a button within a particular repeater container and only that button is activated (using repeater selector type of code). My dilemma now is figuring out how to input the venue name as a field value within my form database. Your code above has allowed me to set a user input text box element into my repeater and custom indicate that the text will show the custom name of the venue for the container in which it resides (i.e. if the input box is in the repeater container for "Venue X," then the input box will show Venue X's name). I've then connected this input box to be sent to the form database upon my button click event. All other form input elements, which reside outside of my repeater, are sent to the form database upon button click - however - my venue name (which resides within my repeater) is not being sent as well. Besides not being sent, it is also resetting after I click the button - all the venue names for every repeater is being reset (not just the name in the container I happen to be clicking on). Do you know what I can do to also have the venue name sent to the form database, along with the other form input elements? I've been trying to figure this out for a really long time and I feel like I've ALMOST got it, I just can't figure out how to send the venue name as well. Yesrael (or anyone who has an answer), I would be tremendously grateful for any assistance, thank you!!!
0
0

Chanel

More actions
bottom of page