Search code examples
jqueryhtmlrateyo

Rate Yo! - click add disabled


I have a problem with Rate Yo!

When the user clicks on the stars, the rating is added.

After clicking I would like to add an attribute to id="rateYo" (data-rateyo-read-only = "true"): http://rateyo.fundoocode.ninja/#option-readonly - which blocks the possibility of voting again.

My code is:

$ ("#rateYo").click (function () {
    $ ('#rateYo').attr('data-rateyo-read-only','true');
});

Solution

  • No need of manully adding disable attribute.Use onSet event - when user give rating make it readonly through rateYo("option", "readOnly", true);

    $("#rateYo").rateYo({
        onSet: function (e, data) {
           alert("The rating is set to " + data.rating() + "!");
           $(this).rateYo("option", "readOnly", true);  // make readonly
        },
        starWidth: "24px"
    });
    

    You can also do like this if you have already initialized it

    $("#rateYo").rateYo('option', 'readOnly', true); // disable (make readonly)
    
    $("#rateYo").rateYo('option', 'readOnly', false); // enable
    

    http://jsfiddle.net/mogxa8rd/