Magento 1.9 – Set Custom Star Review Rating as Required Entry

magento-1.9ratingsreview

I'm using Clickable star ratings for my e-commerce web site. I have followed the instructions provided within this tutorial:

http://blog.youbility.de/en/clickable-star-ratings-in-magento/

Now I'm trying to accomplished that star rating is required entry. So when I use the class name "required-entry" in the following code of line:

<input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio rating-input" />

just at the end of the code where is says: class=radio rading-input i have made the change so it looks: class=radio rading-input required-entry

Now star rating becomes required-entry, but it becomes required-entry for all the five starts – and i need to make five stars required-entry as one field.

Thanks.

Best Answer

I did same thing but the different way. Instead of putting required-entry class to radio, I add new validation rule to that form.

Please put below code in your review form page, it might be work for you:

<script type="text/javascript">
    //<![CDATA[
    var dataForm = new VarienForm("review-form", true);

    Validation.addAllThese(
            [
                ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function (v) {
                            return false;

                }]
            ]
            );
    //]]>
</script>

Here is the output of validation: enter image description here

Let me know if you have query for the same.


For single rating option:

enter image description here

Related Topic