Ajax functionality needs to be added to the core of this plugin, but in the meantime this code will cause validation errors to display without reloading the page.
The jQuery Validate plugin is needed for this code to work.
// add "required" attribute to the inputs and textareas that should be required
$('.rr_review_form .rr_required + .rr_form_input > input, .rr_review_form .rr_required + .rr_form_input > textarea').attr('required', 'required');
// [IF USING STARS] add an input so stars can be validated
$('.rr_stars_container').append('<input type="checkbox" name="input_stars" style="opacity: 0;">');
// [IF USING STARS] add a function to remove error when stars are selected
$('.rr_stars_container').click(function() {
if ($('.rr_stars_container').find('.glyphicon-star').length > 0) {
$('input[name="input_stars"]').removeClass('error');
$('label#input_stars-error').hide();
}
});
// [IF USING STARS] add a method to the validate plugin to check for a stars rating
$.validator.addMethod("selectStars", function(value, element) {
return $('.rr_stars_container').find('.glyphicon-star').length > 0;
}, "Please rate this product.");
// validate the form
$('.rr_review_form').validate({
// [IF USING STARS] add a method to the validate plugin to check for a stars rating
rules : {
input_stars : { selectStars : true }
}
});