top of page

Forum Posts

RT
Jan 17, 2023
In Coding with Velo
https://www.wix.com/velo/forum/coding-with-velo/solution-adding-separate-ratings-and-reviews-to-individual-dynamic-pages PLEASE READ THE ABOVE POST TITLED "SOLUTION: Adding Separate Ratings and Reviews to Individual Dynamic Pages" FIRST FOR THE INTITIAL STEPS. THIS POST IS JUST UPDATES TO THAT POST, WITH FIXES TO THE ISSUES I ENCOUNTERED. I think I finally fixed all of them. I have tested out the pages and the ratings and comments system many times and it all seems to be working. I am complete beginner, so please excuse any mistakes, if you find any 🙂. This is the url for the dynamic list page on our website: https://www.collaborativediscussionproject.com/activities/module-1 This is the url for the dynamic item page on our website: https://www.collaborativediscussionproject.com/items-1/1.1-what-is-collaborative-learning%3F After I created the initial solution (mentioned in the SOLUTION post I linked above), when I was testing it again, my ratings display (yellow stars) were just going blank. To fix this, I first did two things: 1) Increased the time given to run the code - so wherever it says "setTimeout(function)", at the end there is a number in the thousands. It used to be 5000 or 1500, I increased these numbers to 9000 and 20000. This does make it so it takes a little time for the number of comments to calculate, but I don't think it is too noticable and it was the only thing that I could figure out to fix the problem. 2) Made the entering a rating required - because if a comment is submitted without a rating being entered, with the code I used from the Velo tutorial to calculate the average rating, it doesn't know what to do when no rating is entered. So, I made the rating required, by adding code to disable the submit button and only enable it once a rating is selected. In the final code below, I added this snippet/part in the onReady function to disable the button initially when the page is loaded and no rating has been selected: // get the new rating from the ratings input const newRating = $w('#commentsRatingsInput').value; if (newRating > 0) { $w('#addCommentButton').enable() } else { $w('#addCommentButton').disable() $w('#commentsRatingsInput').required = true; } I also added the following snippet to enable the Submit button once a rating is selected: export function commentsRatingsInput_change(event) { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: const newRating = $w('#commentsRatingsInput').value; if (newRating > 0) { $w('#addCommentButton').enable() } else { $w('#addCommentButton').disable() $w('#commentsRatingsInput').required = true; } } IMPORTANT: I also changed the Permissions of my CommentRatings collection so that is says Anyone can update content, since in this collection - each item/page has one line where the values in the avg, numRatings, and totalRatings keep updating everytime someone enters a rating. So, unlike other collections (like the Comments collection) where everytime someone enters a comment a new line is added, since this CommentRatings collection just updates the same line, you need to give permission to Anyone to update content, not just to view or add content: Another issue I was having was that after a rating is selected, a name and comment entered and submitted, the ratings stars would still show the value that was selected and the name and comment box would be outlined it red - so I needed add code to reset the ratings star value to null and the reset the validity of the name and comment input boxes. This is code I added in the .then part in my code: $w('#commentsRatingsInput').value = null $w('#commentsInput').resetValidityIndication() $w('#nameInput').resetValidityIndication() THIS IS THE COMPLETE FINAL CODE ADDED TO THE DYNAMIC ITEM PAGE (i.e. the page with the Ratings input element and Name and Comments input boxes): // Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction import wixData from 'wix-data'; $w.onReady(function () { // TODO: write your page related code here... //loadrating () // get the new rating from the ratings input const newRating = $w('#commentsRatingsInput').value; if (newRating > 0) { $w('#addCommentButton').enable() } else { $w('#addCommentButton').disable() $w('#commentsRatingsInput').required = true; } setTimeout(function() { let totalCount = $w("#dataset1").getTotalCount(); $w('#commentsCountBox').text = totalCount.toString() + " comment(s)" }, 9000); }); export function commentsRatingsInput_change(event) { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: const newRating = $w('#commentsRatingsInput').value; if (newRating > 0) { $w('#addCommentButton').enable() } else { $w('#addCommentButton').disable() $w('#commentsRatingsInput').required = true; } } export function addCommentButton_click(event) { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: //$w('#loader').show() // get the new rating from the ratings input const newRating = $w('#commentsRatingsInput').value; $w("#commentRatingsdataset").onReady(() => { // get the current item from the dataset const currentItem = $w("#commentRatingsdataset").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; // 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('#commentRatingsdataset').setFieldValues({ 'avg': newAverageShort, 'totalRatings': total + newRating, 'numRatings': (count + 1) }); // save the dataset fields to the collection $w('#commentRatingsdataset').save() .catch((err) => { console.log('could not save new rating'); }); }); $w('#addCommentButton').disable() let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; wixData.insert('comments',{ 'comment': $w('#commentsInput').value.replace('Nigga', '').replace('nigga', '').replace('Nigger', '').replace('nigger', '').replace('Fuck', '').replace('fuck', ''), 'userName' : $w('#nameInput').value, 'rating' : $w('#commentsRatingsInput').value, 'pageId' : pageId, 'pageReference' : pageId, }) .then( () => { $w('#commentsInput').value = '' $w('#nameInput').value = '' $w('#commentsRatingsInput').value = null $w('#commentsInput').resetValidityIndication() $w('#nameInput').resetValidityIndication() $w('#dataset1').refresh() setTimeout(function() { $w('#addCommentButton').enable() //$w('#loader').hide() let totalCount = $w("#dataset1").getTotalCount(); $w('#commentsCountBox').text = totalCount.toString() + " comment(s)" }, 20000); }) //wixData.insert('CommentRatings', { //'pageId' : pageId, // 'pageReference' : pageId, //}) } function filterComments () { let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; $w('#dataset1').setFilter( wixData.filter() .contains("pageId", pageId) ).then(() => { setTimeout (function() { }, 20000); }); } export function dataset1_ready() { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: filterComments() } function filterCommentRatings () { let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; $w('#commentRatingsdataset').setFilter( wixData.filter() .contains("pageId", pageId) ).then(() => { setTimeout (function() { }, 20000); }); } export function commentRatingsdataset_ready() { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: filterCommentRatings () } /** * Adds an event handler that runs when an input element's value is changed. [Read more](https://www.wix.com/corvid/reference/$w.ValueMixin.html#onChange) * @param {$w.Event} event */ TO ADD THE AVERAGE RATINGS DISPLAY TO THE DYNAMIC LIST PAGE'S REPEATER ITEMS: First, I went into my CommentRatings collection that is used to store, calculate and display the average rating and number of ratings for each dynamic item page (in my case, each activity's page), and clicked on More Actions, then Export to CSV and exported all the fields and data into a .CSV file. I then opened it using Excel and saved it as an excel file. I then deleted all the other fields and data (i.e. columns in excel) except the pageId and Page Reference fields. I then sorted the whole excel sheet by going to the top menu in Excel, then Data > Sort. I clicked my table has headers and sorted by the Page Reference field, A to Z, so all the data was in order of my pages since they all start with a number (i.e 1.1, 1.2 etc.). I then went to my dynamic list page: URL: https://www.collaborativediscussionproject.com/activities/module-1 On the dynamic list page, in the collection for this page, in my case called Activities, I added a reference field that references the CommentRatings collection that is used to store, calculate and display the average rating and number of ratings for each dynamic item page (in my case, each activity's page): I then copied and pasted the page IDs from the PageId field next to the matching item page in the my Activities collection: So, I'm not totally sure about this, because I can't completely remember how I did it - but I think if you have the data i.e. page title and IDs in the excel file in the same order as the pages in the collection storing your item pages, you can copy and paste more than one line/cell at a time of Page IDs from the pageId column in the excel file into the Ratings Reference field in the items collection - in my case, the Activities collection. If this doesn't work, then you have to copy and paste in the page ID for each page one at a time. HOWEVER YOU COPY AND PASTE, MAKE SURE TO DOUBLE CHECK EVERY SINGLE ONE OF YOUR PAGE IDS TO MAKE SURE IT MATCHES THE CORRECT PAGE - I obsessively did this like two or three times, lol! 🤣 IMPORTANT NOTE: EVERY TIME YOU ADD A NEW ITEM TO YOUR DYNAMIC PAGES COLLECTION, YOU NEED TO ADD A NEW LINE AND SELECT THE PAGE IN THE PAGE REFERENCE FIELD AND ADD THE PAGE ID IN THE pageId FIELD IN THE COLLECTION STORING YOUR AVERAGE RATING AND NUMBER OF RATINGS (in my case the CommentRatings collection) AND THEN ADD THE PAGEID FROM THIS COLLECTION IN THE Ratings Reference field IN THE DYNAMIC PAGES COLLECTION (in my case, the Activities collection)! Then you need to add a ratings display element to the repeater item on your dynamic page: Because my repeater items are small, there is not enough space to show the number of ratings on the side, so I toggled this off in the Settings for the Ratings display element: I then connected the Ratings display element to the Activities dataset and chose Ratings Reference: avg under Rating value connects to: This will pull in the value from the "avg" field (1st column/field) in my CommentRatings collection and use that to show the average rating for each page/item in the Ratings display (i.e 5.0 right now in my case): I then added two text boxes underneath and grouped them together - one text box (on the right) says "rating(s)". The other text box on the left, I connected to the Activities dataset and chose Ratings Reference: numRatings under Text connects to: This will pull in the value from the "numRatings" field (2nd column/field) in my CommentRatings collection and use that to show the number of ratings for each page/item in the Ratings display (i.e mostly 1 or 2 right now in my case): IMPORTANT NOTE: EVERY TIME YOU ADD A NEW ITEM TO YOUR DYNAMIC PAGES COLLECTION, YOU NEED TO ADD A NEW LINE AND SELECT THE PAGE IN THE PAGE REFERENCE FIELD AND ADD THE PAGE ID IN THE pageId FIELD IN THE COLLECTION STORING YOUR AVERAGE RATING AND NUMBER OF RATINGS (in my case the CommentRatings collection) AND THEN ADD THE PAGEID FROM THIS COLLECTION IN THE Ratings Reference field IN THE DYNAMIC PAGES COLLECTION (in my case, the Activities collection)! I think this covers everything I did - I hope it does, hehe 😅...- It has been a while, because I was buried under everything I had to do for the relaunch of our website in December and wanted to wait till other people started entering ratings and reviews, to make sure everything was working, before I posted the fixes to the issues I found in this forum. If you have any questions, please leave them in the comments and I will try to answer if I know the answer - again, I'm just a beginner, so I might not. Hope this helps!!! Have fun!
UPDATED SOLUTION: Adding Separate Ratings and Reviews to Individual Dynamic Pages and Dynamic List Page Repeater Items

 content media
1
2
242
RT
Nov 07, 2022
In Coding with Velo
Hi, I finally figured out some kind of solution for adding ratings and reviews to individual dynamic pages and wanted to share it. It's not perfect - there is one bit where you have to enter some content into a collection manually, but this was the only solution I could figure, so.... Hope this helps everyone, especially other total beginners like me! Thank you to Lytude channel on Youtube for his videos, which really helped, and all the other forum members who posted about this topic!! (This is going to be a bit of a complicated/long explanation - hope it's not too confusing and please read the whole post to see the final combined/edited code) This is what my final page looks like now: The Ratings Display element showing the Average Rating and the Total Number of Ratings is circled in red: Below the grey strip with the Activity's information/content, I added another strip to hold the Ratings and Comments Input Fields and the Repeater that displays all the ratings and comments: HOW I MANAGED TO CREATE THIS WAS: I first found these videos on Youtube and followed what is shown and edited the code he shows and links to in the description of the Part 3 and 4 videos... (there is a Part 5 as well, which I didn't need/use) PLEASE SEE THE BOTTOM OF THE POST FOR THE EMBEDED VIDEOS :) Like he shows in the videos, I created a Comments collection with a Reference field that references the collection that contains all the items shown on my dynamic pages (In my case, Activities, like 1.1 What is Collaborative Learning?, 1.2 Developing Collaborative Perspective, etc.) Comments Collection: Activities Collection - referenced in the Page Reference field above in the Comments collection: When creating the Comments collection - my screens and where I had to go to select the Permissions on who can view, add, delete, and update content were a little different from what is shown in the video. The Permissions is not shown/available to select on the Create Collection window: So after entering the info, you need to click Create and then when the collection window opens (or you go to the side menu and open the collection) There you click on More Actions > Permissions and Privacy, which will open that tab in the Edit Collection Settings window: Since, unlike in the videos, I want to allow anyone to add a comment, and not just site members/people who are logged into my site (I do not have this option on my website), I selected Anyone for view, Anyone for add, Admin for delete and Admin for update content, as shown in the screenshot. Also, in addition to the fields mentioned in the video, I added an additional field called Rating with the field type set to Number to collect the rating values that users input and another field called User Name to collect the name that users input in the Name Input element/box(shown above my comments input box). Also, in the repeater element that displays all the comments entered, I added a Ratings Display element and made sure to attach it to the item, so it repeats in each item in the repeater. I then clicked Settings and turned off the Show the number of ratings option (since I am showing the individual rating entered by each user here) - see the screenshot below: I also then edited the code provided in the description of the PART 3 video, to take out all the elements/features I did not need, like member's profile id or picture etc, the loader icon, disabling comments if the user is not logged in and enabling them if they are, etc. and added in the code to insert the rating value that the user selects into my Comments Collection. NOW, HERE IS WHERE THIS MIGHT GET A LITTLE COMPLICATED/CONFUSING (it was for me when I was figuring it out, lol!): TO ADD THE AVERAGE RATING AND TOTAL NUMBER OF RATINGS: I first created a second collection following the first part of this tutorial and then combined the code from this tutorial with the code from the videos: https://support.wix.com/en/article/velo-tutorial-capturing-and-displaying-ratings I called the second collection CommentRatings, and added the three Number type fields for the average rating, the total number/count of ratings, the total sum of ratings. To keep it simple, I just named my fields avg, numRatings, and totalRatings, so I would not need to do too much substitution in the code. In addition to what is in the tutorial article, I also added a Text type field called pageId and Reference type field called Page Reference and linked this reference field to my dynamic page collection (in my case the Activities collection), the same way shown in the Youtube video for the first Comments collection: CommentsRating collection with arrows pointing to the 2 extra fields I added: I then added a dataset, with the settings shown in the screenshot, to my page to link to the CommentRatings collection and linked the parts of the Ratings Display element to the avg and numRatings field: And connected the top of the page RatingsDisplay element to the dataset as shown in this screenshot: And edited the settings of the Ratings Display element so the Ratings text label shows "ratings", not "Product ratings". This is optional, you don't have to change it if you don't want to. SO, AT THIS POINT, WE HAVE CREATED ALL THE COLLECTIONS AND DATASETS ETC. Now we can add the code. After all the editing and combining of the code from the videos and the Velo tutorial article, my final code looks like this: import wixData from 'wix-data'; $w.onReady(function () { // TODO: write your page related code here... setTimeout(function() { let totalCount = $w("#dataset1").getTotalCount(); $w('#commentsCountBox').text = totalCount.toString() + " comments" }, 5000); }); export function addCommentButton_click(event) { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: //$w('#loader').show() $w('#addCommentButton').disable() let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; wixData.insert('comments',{ 'comment': $w('#commentsInput').value.replace('Nigga', '').replace('nigga', '').replace('Nigger', '').replace('nigger', '').replace('Fuck', '').replace('fuck', ''), 'userName' : $w('#nameInput').value, 'rating' : $w('#commentsRatingsInput').value, 'pageId' : pageId, 'pageReference' : pageId, }) .then( () => { $w('#commentsInput').value = '' $w('#nameInput').value = '' $w('#dataset1').refresh() setTimeout(function() { $w('#addCommentButton').enable() //$w('#loader').hide() let totalCount = $w("#dataset1").getTotalCount(); $w('#commentsCountBox').text = totalCount.toString() + " comments" }, 2000); }) //wixData.insert('CommentRatings', { //'pageId' : pageId, // 'pageReference' : pageId, //}) $w("#commentRatingsdataset").onReady(() => { // get the current item from the dataset const currentItem = $w("#commentRatingsdataset").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('#commentsRatingsInput').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('#commentRatingsdataset').setFieldValues({ 'avg': newAverageShort, 'totalRatings': total + newRating, 'numRatings': (count + 1) }); // save the dataset fields to the collection $w('#commentRatingsdataset').save() .catch((err) => { console.log('could not save new rating'); }); }); } function filterComments () { let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; $w('#dataset1').setFilter( wixData.filter() .contains("pageId", pageId) ).then(() => { setTimeout (function() { }, 1500); }); } export function dataset1_ready() { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: filterComments() } function filterCommentRatings () { let page = $w("#dynamicDataset").getCurrentItem(); let pageId = page._id; $w('#commentRatingsdataset').setFilter( wixData.filter() .contains("pageId", pageId) ).then(() => { setTimeout (function() { }, 1500); }); } export function commentRatingsdataset_ready() { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: filterCommentRatings () } (Tip for beginners like me: everything with // before it is commented out, this means this code will not run or they are just used to enter text describing/adding notes to the code - basically this is not part of the code that runs on your website) Explanation for what the different element ids are referring to in the code, so you know what to substitute in your code: #dataset1 is the id for Comments dataset that is connected to the Comments collection (the first collection I created by following the videos; this id is the same as the one used in his code) #commentsCountBox is the id for the text box (above the comment display repeater) that shows the number of comments: So, in the code above, the piece of code shown below, is basically saying get the total count/number of items in the Comments collection (using dataset1) and return that number/value in the text box that shows the number of comments (commentsCountBox) and then put a space and the word comments after the number: let totalCount = $w("#dataset1").getTotalCount(); $w('#commentsCountBox').text = totalCount.toString() + " comments" }, 5000); #dynamicDataset is the dataset that brings the content on the dynamic page, so in my case this is the Activities dataset, which is connected to the Activities collection - the red arrow is pointing to the id: In the code wixData.insert ('comments' 'comments' is the id for the Comments Collection and under that 'comment', 'userName', 'rating', 'pageId', 'pageReference' are all the ids for each field in the Comments Collection. You can see I added the following code in between the code from the video to insert the name users type into the Name Input box and the rating they select into the Comments Collection: 'userName' : $w('#nameInput').value, 'rating' : $w('#commentsRatingsInput').value, Here #nameInput is the id for Name Input box and #commentsRatingsInput is the id for the Comments Input box - red arrows below: #commentsInput is the id for the Comment Input box - red arrow below #commentRatingsdataset is the id for the CommentRatings dataset that is connected to the second collection CommentRatings which has the avg, numRatings, totalRatings fields used to calculate the Average Ratings and Number of Ratings values for the Ratings Display element at the top of the page: NOW, HERE COMES THE MANUAL PART I MENTIONED: For the top Ratings Display element to correctly show the Average Rating and the total number of ratings, I needed to manually add in some content in the CommentRatings collection: For each item in my Activities collection that the Page Reference field in my CommentRatings collection is referring to, I had to add a line/row, and enter a beginning/dummy values for the avg, numRatings, and totalRatings field. As you can see in the screenshot above: For the Page Reference field, I selected each item title in order, in my case, the activity from the dropdown - if you start typing the name of the item, it will show up and you can click on it. For the pageId text field, I entered each item (in my case activity's) ID, which I copied from the Activities collection, by doing the following: I opened the Activities Collection, clicked on Manage Fields, scrolled down till I found the ID field and clicked the checkbox next to it so it becomes visible in my collection. I opened the Activities Collection, clicked More Actions > Export to CSV I then opened this .csv file and saved it as an Excel file and deleted all the fields in between my Activity Title and the ID field Then I sorted the whole worksheet by the Activity title (basically so rows in the excel file would be in the same order as the Page Reference field values in CommentRatings Collection) I then selected all the values/rows in the ID field in my excel file, did crtl + C to copy, came to my CommentRatings collection window, selected all the rows under pageId and did ctrl + V to paste in all the ID values for each item, in my case, next to the corresponding Activity title selected in the Page Reference field Then, I just added 5 for avg (the average rating), 1 for numRatings (the total number of rating - here just 1) and 5 for totalRatings (since there is only one rating of 5 - this dummy rating) for every row/item, in my case every activity. Without this one row for each item, in my case activity, the average ratings value and total number of ratings value just don't display on the top of the page Ratings Display element. Now, this means that it will show 1 rating at the top, even if there are no comments entered yet by users/visitors and the count at the top will sometimes be 1 more than the actual number of comments (I don't know why)....but it was the best solution I could figure out :) After all this, each dynamic page should now display the average ratings, total number of ratings at the top and each individual name, rating and comment at the bottom of the page entered for each item on each item and only those entered for that item on that page and not any other items. For example, on my dynamic item pages... It shows 3.3 average rating and 3 ratings for the Activity 1.2 page at the top, and each individual rating and comment at the bottom: and for the Activity 1.3 page - it is showing something different, i.e. the average rating = 3.7 and total ratings = 3 and individual ratings and comments only for this Activity 1.3 and no other Activities: I really hopes this helps out others who are I struggling with getting these ratings and reviews like I was :) Thank you again for everyone's posts that helped me figure out this solution! VIDEOS: Add comment section to wix dynamic page videos: PART 1 PART 2 (even though it says Part 3 on the image) PART 3 PART 4
0
6
359
RT
Nov 06, 2022
In Coding with Velo
I am completely new to Wix and Velo. I do not know any coding at all, but I was told the only way to add what I want to my website was to use code (the Editor and third party apps do not work for what I want). Using the Wix Editor, I created dynamic list pages that lists multiple activities from an Activities Collection and dynamic items pages that shows detailed information for each activity. This is the screenshot of the Activities Collection: The Activity Title field is the primary field with the field key "title". This is the dynamic category list page that lists the activities by Module (i.e. Module 1, Module 2 etc. values shown in the Module field) for each activity. This is the dynamic item page that shows the detailed content for each activity (like Activity Title, Activity Short Description etc). On each activity's page, under all the information, I want to add the option for users to add and view ratings and reviews for each activity on each activity dynamic item page, so that each page for each activity shows only the ratings and reviews submitted for that activity on that page and not show all the reviews submitted for all the activities on every activity page. I found an old forum post https://www.wix.com/velo/forum/coding-with-velo/comments-reviews-on-dynamic-pages If you scroll down on this page, there is a reply by Franz Coester on Sep 16, 2019 that includes some code on how to add ratings and reviews on dynamic pages. Since I don't really know much about coding, I don't know how to edit this code to change the ids to refer to the items on my page, or the fields in my collections or anything... I tried creating a Ratings collection like he says with a Reference back to my Activities collection (in his case his harbors collection/table), by adding a field in the collection, selecting the Field Type as Reference and selecting Activities collection under Referenced collection (please see screenshots below - the reference field is circled in red) But I don't know if I am doing this correctly or not, because in the screenshots from Franz Coester in the old forum post, the reference field is showing a database icon, while my reference field is showing some kind of link icon: Frank Coester's rating's collection with reference field My Ratings collection reference field: This is part of the code he used load the rating to display the average and total number of ratings on the dynamic item page for each harbor: $w.onReady(function () { $w('#harbouritem').onReady(() => { harbouritem = $w('#harbouritem').getCurrentItem() loadrating() }) }); exportfunction loadrating() { let ratings; wixData.query('Ratings') .eq('harbours',harbouritem._id) .find() .then(result => { ratings = result.items let sumrating = 0 let countrating = 0 let rating = 0 countrating = result.totalCount result.items.forEach(res => { sumrating += res.rating }) if (sumrating,countrating) {rating = sumrating/countrating} $w('#harbourrating').numRatings = countrating if (rating > 0) { $w('#harbourrating').rating = rating } else { $w('#harbourrating').rating = undefined } }) } I am having trouble understanding all the different things he is referring to in his code, like I don't know what '#harbouritem', 'Ratings','harbours', harbouritem._id, '#harbourrating' mean - are they the ids for elements on the page, the names of collections, fields from his collections or something else??? I also don't know how to refer to a field in my collections in the code - like what the syntax is... The # symbol seems to only work to refer to the ids of elements on the actual page, not a field in a collection. Because I am not understanding what he is referring to in his code, I also don't know what ids or code to substitute in his code so the code works with my collections, page elements etc. So, I just need help from someone who can explain what each part of the code means and what I need to substitute to make it work for my website's pages. I greatly appreciate any help. Thank you so much, RT
Adding Separate Ratings and Reviews to Dynamic Item Pages content media
0
3
50

RT

More actions
bottom of page