barbatus/stars-rating

Unable to fetch the value of stars

Opened this issue · 2 comments

It looks like i m unable to fetch the value of stars by id or by currentTarget method. i follow the exact code as written in the description.please help.

Add the id.The unique id is the id that Mongodb provides
{{> starsRating id=_id mutable=true}}
Here we are working with the template. For example - if there is an image template and you have lots of images. Each image will have a unique id so this id will be same for the starRating template.

code example -

<template name="images">
<div class="col-xs-12" id="{{_id}}">
    <div class="thumbnail">

        <img class="js-image" src="{{img_src}}" 
        alt="{{img_alt}}" /> 

        <div class="caption">
                    <h3>Rating: {{rating}}</h3>
               <p>{{img_alt}}</p>

           <p>
            {{>starsRating mutable=true class="js-rate-image" id=_id}}
          </p>
</div>
</template>

Then apply a class to your starsRating template like {{>starsRating mutable=true class="js-rate-image" id=_id}}. Now you can modify its behaviour in the js file like

var rating = $(event.currentTarget).data("userrating"); . Now update using update method in mongo.

And don't forget mutable="true" as this will allow the user to set a rating.

Put this to the documentation:

To get the value of the current rating from javascript use inside the change callback:
$(event.currentTarget).data("userrating");