Fixes rating javascript

This commit is contained in:
Mouse Reeve 2020-04-04 10:08:34 -07:00
parent 458e71a41e
commit e66adc7d74
2 changed files with 4 additions and 4 deletions

View File

@ -37,13 +37,13 @@ function reply(e) {
return true; return true;
} }
function rate(e) { function rate_stars(e) {
e.preventDefault(); e.preventDefault();
ajaxPost(e.target); ajaxPost(e.target);
rating = e.target.value; rating = e.target.rating.value;
var stars = e.target.parentElement.getElementsByClassName('icon'); var stars = e.target.parentElement.getElementsByClassName('icon');
for (var i = 0; i < stars.length ; i++) { for (var i = 0; i < stars.length ; i++) {
stars[i].className = rating < i ? 'icon icon-star-full' : 'icon icon-star-empty'; stars[i].className = rating > i ? 'icon icon-star-full' : 'icon icon-star-empty';
} }
return true; return true;
} }

View File

@ -2,7 +2,7 @@
<span class="hidden-text">Leave a rating</span> <span class="hidden-text">Leave a rating</span>
<div class="stars rate-stars"> <div class="stars rate-stars">
{% for i in '12345'|make_list %} {% for i in '12345'|make_list %}
<form name="rate" action="/rate/" method="POST" onsubmit="return rate(event)"> <form name="rate" action="/rate/" method="POST" onsubmit="return rate_stars(event)">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.fedireads_key }}"></input> <input type="hidden" name="book" value="{{ book.fedireads_key }}"></input>
<input type="hidden" name="rating" value="{{ forloop.counter }}"></input> <input type="hidden" name="rating" value="{{ forloop.counter }}"></input>