Skip to content

Commit f505c20

Browse files
committed
MAGETWO-54186: Problem with js validation when adding product to shopping cart
1 parent 8ebadcd commit f505c20

File tree

1 file changed

+23
-8
lines changed
  • app/code/Magento/Catalog/view/frontend/templates/product/view

1 file changed

+23
-8
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</div>
4141
</div>
4242
<?php endif; ?>
43+
<?php if ($block->isRedirectToCartEnabled()) : ?>
4344
<script type="text/x-magento-init">
4445
{
4546
"#product_addtocart_form": {
@@ -49,14 +50,28 @@
4950
}
5051
}
5152
</script>
52-
<?php if (!$block->isRedirectToCartEnabled()) : ?>
53-
<script type="text/x-magento-init">
54-
{
55-
"#product_addtocart_form": {
56-
"catalogAddToCart": {
57-
"bindSubmit": false
53+
<?php else : ?>
54+
<script>
55+
require([
56+
'jquery',
57+
'mage/mage',
58+
'Magento_Catalog/product/view/validation',
59+
'Magento_Catalog/js/catalog-add-to-cart'
60+
], function ($) {
61+
'use strict';
62+
63+
$('#product_addtocart_form').mage('validation', {
64+
radioCheckboxClosest: '.nested',
65+
submitHandler: function (form) {
66+
var widget = $(form).catalogAddToCart({
67+
bindSubmit: false
68+
});
69+
70+
widget.catalogAddToCart('submitForm', $(form));
71+
72+
return false;
5873
}
59-
}
60-
}
74+
});
75+
});
6176
</script>
6277
<?php endif; ?>

0 commit comments

Comments
 (0)