Search code examples
jqueryraty

dynamic readOnly doesn't work


I am trying to read readonly value from attributes and set it in ratys readOnly but no success so far. this is the code I am using and you can see commented lines what I tried.

<script type="text/javascript">
    $(document).ready(function () {
        $('.star').raty({
            path: '/Sources/jquery.raty/img/',
            readOnly: //($(this).attr('data-readonly') === "true"),//$(this).data('readonly'),
            function () {
                //console.log(($(this).attr('data-readonly') === 'true'));
                //return ($(this).attr('data-readonly') === 'true');
            return false;
            }
        }
    });


<div class="rating" style="text-align: center;">
     <div id="ContentPlaceHolder1_Content_rptContent_star_0" class="star" data-rating="3" data-readonly="true" data-uid="54e2d977-be1a-4b39-95f3-2e5c89f106ff" style="cursor: default; width: 100px;" title="regular"><img src="/Sources/jquery.raty/img/star-on.png" alt="1" title="regular">&nbsp;<img src="/Sources/jquery.raty/img/star-on.png" alt="2" title="regular">&nbsp;<img src="/Sources/jquery.raty/img/star-on.png" alt="3" title="regular">&nbsp;<img src="/Sources/jquery.raty/img/star-off.png" alt="4" title="regular">&nbsp;<img src="/Sources/jquery.raty/img/star-off.png" alt="5" title="regular"><input type="hidden" name="score" value="3" readonly="readonly"></div>
</div>

PS: I know how to read an attribute, problem is that doesn't work in raty.

you can check from here https://jsfiddle.net/hLg2cr9v/


Solution

  • Seems to work for me.

    readOnly: function() {
        return $(this).data('readonly');
    }
    

    http://jsfiddle.net/daveSalomon/hLg2cr9v/1/