Skip to content

Commit 423219b

Browse files
Pooja.ManralPooja.Manral
authored andcommitted
AC-10826::Storefront Bundle Checkbox Validation Error message count more than 1
1 parent 7377de5 commit 423219b

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

app/code/Magento/Bundle/view/frontend/requirejs-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ var config = {
1111
slide: 'Magento_Bundle/js/slide',
1212
productSummary: 'Magento_Bundle/js/product-summary'
1313
}
14+
},
15+
config: {
16+
mixins: {
17+
'mage/validation': {
18+
'Magento_Bundle/js/validation': true
19+
}
20+
}
1421
}
1522
};

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@
4646
<?= ' disabled="disabled"' ?>
4747
<?php endif; ?>
4848
value="<?= $block->escapeHtmlAttr($sectionId) ?>"
49-
data-errors-message-box="#validation-message-box"/>
49+
data-errors-message-box="#validation-message-box-<?= $block->escapeHtmlAttr($_option->getId()) ?>"/>
5050
<label class="label"
5151
for="<?= /* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId) ?>">
5252
<span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($selection) ?></span>
5353
<br/>
5454
<?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($selection) ?>
5555
</label>
5656
</div>
57+
5758
<?php endforeach; ?>
58-
<div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div>
59-
<div id="validation-message-box"></div>
6059
<?php endif; ?>
6160
</div>
61+
<div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div>
62+
<div id="validation-message-box-<?= $block->escapeHtmlAttr($_option->getId()) ?>"></div>
6263
</div>
6364
</div>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
define([
2+
'jquery',
3+
'jquery-ui-modules/widget'
4+
], function ($) {
5+
'use strict';
6+
var enhancedMageValidation = {
7+
/**
8+
* @param {*} error
9+
* @param {*} element
10+
*/
11+
options: {
12+
errorPlacement: function (error, element) {
13+
var errorPlacement = element,
14+
fieldWrapper,messageBox;
15+
16+
// logic for date-picker error placement
17+
if (element.hasClass('_has-datepicker')) {
18+
errorPlacement = element.siblings('button');
19+
}
20+
// logic for field wrapper
21+
fieldWrapper = element.closest('.addon');
22+
23+
if (fieldWrapper.length) {
24+
errorPlacement = fieldWrapper.after(error);
25+
}
26+
//logic for checkboxes/radio
27+
if (element.is(':checkbox') || element.is(':radio')) {
28+
errorPlacement = element.parents('.control').children().last();
29+
30+
//fallback if group does not have .control parent
31+
if (!errorPlacement.length) {
32+
errorPlacement = element.siblings('label').last();
33+
}
34+
}
35+
if (element.attr('data-errors-message-box')) {
36+
messageBox = $(element.attr('data-errors-message-box'));
37+
messageBox.html(error);
38+
return;
39+
}
40+
//logic for control with tooltip
41+
if (element.siblings('.tooltip').length) {
42+
errorPlacement = element.siblings('.tooltip');
43+
}
44+
//logic for select with tooltip in after element
45+
if (element.next().find('.tooltip').length) {
46+
errorPlacement = element.next();
47+
}
48+
errorPlacement.after(error);
49+
}
50+
51+
}
52+
}
53+
54+
return function (mageValidation) {
55+
$.widget('mage.validation', mageValidation, enhancedMageValidation);
56+
return $.mage.validation;
57+
}
58+
});

0 commit comments

Comments
 (0)