eddysilvamendes / jquery-star-rating-plugin

Automatically exported from code.google.com/p/jquery-star-rating-plugin
0 stars 0 forks source link

Allow programmer to dynamically set rating value #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Thanks for the rating plugin! It's been very useful.

Could you add the ability to dynamically set the rating value using
JavaScript? I retrieve the rating value from my database via ajax and need
to populate the control. 

If there's already a way to do this, could you add an example to your demo
page showing how it's done?

Original issue reported on code.google.com by dean.thr...@gmail.com on 6 Mar 2009 at 10:11

GoogleCodeExporter commented 8 years ago
I would definitely like to see this as well.

Original comment by elimegro...@gmail.com on 11 Mar 2009 at 7:38

GoogleCodeExporter commented 8 years ago
I found a workaround. You can fake a click event on the appropriate star.

    var current = 3; // the current rating
    var el = $(".star_group_yourRating")[current - 1]; // grab the third star
    $.rating.event.click("yourRating", el, {}) // pretend someone clicked it

Still, it'd be nice if there were a built-in way to do this.

Original comment by dean.thr...@gmail.com on 11 Mar 2009 at 9:23

GoogleCodeExporter commented 8 years ago
This is a great suggestion Dean. I do think the best way is to fake a click as 
this 
takes care of all related events (eg.: auto submission, etc). Now all I have to 
do is 
expose an API method to click the relevant element based on...
a) a given index (as your example suggests)
b) a given value (loop through the set and click the one that matches it)
...what do you think?

Original comment by diego.a...@gmail.com on 12 Mar 2009 at 9:24

GoogleCodeExporter commented 8 years ago
I agree! My original task was to do B, set the plug-in according to the current
value. (In my case, the stars went from 1-5, so the index and the value just 
happened
to be the same.)

Original comment by dean.thr...@gmail.com on 12 Mar 2009 at 1:19

GoogleCodeExporter commented 8 years ago
Oh, I should also mention that I used a similar technique to call 
$.rating.event.fill
on a group of read-only stars. This set of stars was used to display the 
average of
all ratings. I didn't want the user to interact with it, but I still needed to 
set
its value programmatically with the values returned from the database.

Original comment by dean.thr...@gmail.com on 12 Mar 2009 at 1:22

GoogleCodeExporter commented 8 years ago
Thanks for the info Dean, I will add this on the next release of the plugin - 
hopefully over the weekend...

Original comment by diego.a...@gmail.com on 12 Mar 2009 at 3:07

GoogleCodeExporter commented 8 years ago
This feature is now available in v3.
See the "API" tab of the documentation here:
http://www.fyneworks.com/jquery/star-rating/

Original comment by diego.a...@gmail.com on 16 Mar 2009 at 5:20

GoogleCodeExporter commented 8 years ago
Thanks, Diego! I've checked out the new API. Looks great!

Original comment by dean.thr...@gmail.com on 16 Mar 2009 at 6:17