Skip to content

Commit

Permalink
Make the rating validation message translatable (improved): use valid…
Browse files Browse the repository at this point in the history
…ation method)
  • Loading branch information
Echron committed Sep 26, 2017
1 parent a986aa9 commit eb63bbb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Review/view/frontend/templates/form.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
id="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>"
value="<?= $block->escapeHtmlAttr($_option->getId()) ?>"
class="radio"
data-validate="{required:true, messages:{required:'<?php echo __('Please select one of each of the ratings above.'); ?>'}}"
data-validate="{ 'rating-required':true}"
aria-labelledby="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label <?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>_label" />
<label
class="rating-<?= $block->escapeHtmlAttr($iterator) ?>"
Expand Down Expand Up @@ -85,7 +85,8 @@
"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
},
"#review-form": {
"Magento_Review/js/error-placement": {}
"Magento_Review/js/error-placement": {},
"Magento_Review/js/validate-review": {}
}
}
</script>
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/Review/view/frontend/web/js/validate-review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'jquery/ui',
'jquery/validate',
'mage/translate'
], function ($) {
'use strict';

$.validator.addMethod(
'rating-required', function (value) {
return value !== undefined;
}, $.mage.__('Please select one of each of the ratings above.'));
});

0 comments on commit eb63bbb

Please sign in to comment.