NikkiC Posted May 29, 2017 Report Share Posted May 29, 2017 Hi there, I posted this over in the general forum last week, but have had no response so thought it would be better off here! I'm really stumped I'm trying to add a graphic star rating system to my site. I've found the following: http://callmenick.com/post/five-star-rating-component-with-javascript-css which gets me about halfway there, but I just need some slight modifications! This is what I have in my datapage so far: <div id="el" class="c-rating"></div> <script src="http://www.cambridgedata.org/Testboard/manager/five-star-rating-master/js/dist/rating.min.js"></script> <script> // target element var el = document.querySelector('#el'); // current rating, or initial rating var currentRating = [@field:QA_Tester_Rating#]; // max rating, i.e. number of stars you want var maxRating= 5; // callback to run after setting the rating var callback = function(rating) { alert(rating); }; // rating instance var myRating = rating(el, currentRating, maxRating, callback); </script> Where the field QA_Tester_Rating is the field in my table I want to read from and update using this system. At present, it reads from the field fine when there is something already in there, but if the field is blank, the stars don't show at all, so this is my first problem - I'd like the 5 stars to appear, empty, on the page when there is no rating yet. The second issue is that it's not updating my table. I tried adding something along these lines: document.getElementById("EditRecordQA_Tester_Rating").value=myRating; But my javascript is terrible and it obviously didn't work. Last issue, I would like to remove the popup alert when you change the rating. I thought it would be as simple as removing the bit that says: { alert(rating); } But that didn't work either! Any help you can give would be much appreciated! Nikki Quote Link to comment Share on other sites More sharing options...
NikkiC Posted May 31, 2017 Author Report Share Posted May 31, 2017 I've managed to get the rating to update back to the database thought I'd post in case anybody else finds it useful: <div id="el" class="c-rating"></div> <script src="http://www.cambridgedata.org/Testboard/manager/five-star-rating-master/js/dist/rating.min.js"></script> <script> // target element var el = document.querySelector('#el'); // current rating, or initial rating var currentRating; if ([@field:QA_Tester_Rating#] > 0) { currentRating = [@field:QA_Tester_Rating#]; } else { currentRating = 0; } // max rating, i.e. number of stars you want var maxRating = 5; // callback to run after setting the rating var callback = function(rating) {document.getElementById("EditRecordQA_Tester_Rating").value=(rating); }; // rating instance var myRating = rating(el, currentRating, maxRating, callback); </script> Only thing that's not working is making the value 0 if the field is empty. So if the field in the table is empty (as it is by default) then the stars don't show at all. Can anyone help with this bit? // current rating, or initial rating var currentRating; if ([@field:QA_Tester_Rating#] > 0) { currentRating = [@field:QA_Tester_Rating#]; } else { currentRating = 0; } Many thanks! lmooring 1 Quote Link to comment Share on other sites More sharing options...
NikkiC Posted May 31, 2017 Author Report Share Posted May 31, 2017 No worries, I've done this too! Quote Link to comment Share on other sites More sharing options...
GoodBoy Posted June 8, 2021 Report Share Posted June 8, 2021 Hello! Just to add, Caspio now offers customization regarding on what you are trying to achieve. Here's the link: https://www.caspio.com/services/request-info/?e=Star Rating Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.