barbatus / stars-rating

Stars rating control for Meteor
MIT License
21 stars 11 forks source link

[Question] How to set a default rating without triggering the 'change' event ? #17

Closed Ilshidur closed 1 year ago

Ilshidur commented 8 years ago

It's all in the title. I just want to set the default rating to the value the user set before.

Use case :

How can I manage to achieve this ?

shamsahmed commented 8 years ago

I want to know the same.. @Ilshidur did you get a solution? I basically stored the user click in my own collection and want to show the value from my collection on the screen. How do you set the star rating to a value. Example if i pass 3; three starts would be active.

Ilshidur commented 8 years ago

I did not find a workaround for this, sorry. My "solution" was to add a "Submit rate" button below the stars and to set a 'click' listener on this. Therefore, I could set the user vote in the 'onRendering' template function. In this case, I didn't use the 'change' event of this control.

adamgins commented 8 years ago

FYI, I kind of hacked my way around this as was getting a kind of infinite loop. Here's the psuedo-concept:

  1. When the template isCreated I create a reactiveVar that waits (autorun) for the data.
  2. I use the onChange even to set the reactiveVar
  3. when the template (with the rating widget) is onDestroyed I then set the database value to the value stored

    in the reactiveVar.

So this breaks the onChange firing (which it would if you had it wired to the database value).