I am trying to display current rate and allowing re-rating on the same inputs, but it doesn’t work. I could display current rate but disable re-rating or vice versa. I am using that plugin: http://www.fyneworks.com/jquery/star-rating/#tab-API .
Here is what I got:
Here I got version with properly display current rate:
$('.voting-star').rating().rating('select', '3');//
$('.voting-star').rating({
callback: function(value, link){
alert(value);
$.ajax({
url: '/false/address/xxx?rate=' + value + '&photo_id=123425',
});
}
});
And here is version with allowed re-rating (but when site is ready I can see that ‘alerts’ shows many times – and the same number AJAX request is started:
$('.voting-star').rating({
callback: function(value, link){
alert(value);
$.ajax({
url: '/false/address/xxx?rate=' + value + '&photo_id=234234',
});
}
});
$('.voting-star').rating().rating('select', '%{$current_img->getLoggedUserRate()}%');
The problem is that the
callbackfunction is being called multiple times when you callselectthrough the API. You could do something like this instead:Here’s a working example (without AJAX): http://jsfiddle.net/ErmRS/1/