Jump to content

Recommended Posts

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 :unsure:

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

Link to comment
Share on other sites

I've managed to get the rating to update back to the database :D 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!

Link to comment
Share on other sites

  • 4 years later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...