Skip to content

Commit eb63bbb

Browse files
committed
Make the rating validation message translatable (improved): use validation method)
1 parent a986aa9 commit eb63bbb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

app/code/Magento/Review/view/frontend/templates/form.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
id="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>"
3636
value="<?= $block->escapeHtmlAttr($_option->getId()) ?>"
3737
class="radio"
38-
data-validate="{required:true, messages:{required:'<?php echo __('Please select one of each of the ratings above.'); ?>'}}"
38+
data-validate="{ 'rating-required':true}"
3939
aria-labelledby="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label <?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>_label" />
4040
<label
4141
class="rating-<?= $block->escapeHtmlAttr($iterator) ?>"
@@ -85,7 +85,8 @@
8585
"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
8686
},
8787
"#review-form": {
88-
"Magento_Review/js/error-placement": {}
88+
"Magento_Review/js/error-placement": {},
89+
"Magento_Review/js/validate-review": {}
8990
}
9091
}
9192
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'jquery/ui',
9+
'jquery/validate',
10+
'mage/translate'
11+
], function ($) {
12+
'use strict';
13+
14+
$.validator.addMethod(
15+
'rating-required', function (value) {
16+
return value !== undefined;
17+
}, $.mage.__('Please select one of each of the ratings above.'));
18+
});

0 commit comments

Comments
 (0)