Skip to content

Commit

Permalink
Merge pull request #197 from leemyongpakvn/make_rating_mandatory
Browse files Browse the repository at this point in the history
Make rating mandatory
  • Loading branch information
leemyongpakvn authored Feb 6, 2024
2 parents 40614d2 + 357a3f6 commit f2f4d1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions views/css/productcomments.css
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@
font-weight: bold;
}

#ratingNotChosen {
font-size: smaller;
color: #ab4746;
text-align: right;
}

#post-product-comment-form input.error,
#post-product-comment-form textarea.error {
background-color: #f2dede;
Expand Down
1 change: 1 addition & 0 deletions views/js/jquery.rating.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jQuery.fn.rating = function(generalOptions) {
newStar.on('click', function selectGrade() {
var selectedGrade = $(this).data('grade');
ratingInput.val(selectedGrade);
ratingChosen = true;
});
fullStars.append(newStar);
}
Expand Down
15 changes: 14 additions & 1 deletion views/js/post-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ jQuery(document).ready(function () {
const commentPostedModal = $('#product-comment-posted-modal');
const commentPostErrorModal = $('#product-comment-post-error');

const criterionsList = $('#criterions_list');
criterionsList.append('<div id="ratingNotChosen">* ' + productCommentMandatoryMessage + '</div>');
const criterionsInfo = $('#ratingNotChosen');

function showPostCommentModal() {
commentPostedModal.modal('hide');
commentPostErrorModal.modal('hide');
postCommentModal.modal('show');
ratingChosen = false;
criterionsInfo.hide();
}

function showCommentPostedModal() {
Expand Down Expand Up @@ -122,7 +128,14 @@ jQuery(document).ready(function () {
$(fieldSelector).removeClass('error');
$(fieldSelector).addClass('valid');
}
});

if (!ratingChosen) {
criterionsInfo.show();
isValid = false;
} else {
criterionsInfo.hide();
}
});

return isValid;
}
Expand Down
2 changes: 2 additions & 0 deletions views/templates/hook/post-comment-modal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<script type="text/javascript">
var productCommentPostErrorMessage = '{l s='Sorry, your review cannot be posted.' d='Modules.Productcomments.Shop' js=1}';
var productCommentMandatoryMessage = '{l s='Please choose a rating for your review.' d='Modules.Productcomments.Shop' js=1}';
var ratingChosen = false;
</script>

<div id="post-product-comment-modal" class="modal fade product-comment-modal" role="dialog" aria-hidden="true">
Expand Down

0 comments on commit f2f4d1f

Please sign in to comment.