I am trying to add a required checkbox to the checkout summary of magento2, above the submit order button. I have managed to place the checkbox, but the order can still be submitted even if the checkbox is not checked. I have tried everything / searched everywhere but cant seem to figure this one out.
Problem:
- Order can be submitted if checkbox is unchecked
Question:
How do I add a 'required' validation for the checkbox, comparable to the terms & conditions in the image below:
Thanks for the help!
My code: (note: might have allot of redundant 'required' attempts, some css classes are just for styling, even though they make no sense functionally)
(1) app/code/vendor/module/view/frontend/layout/checkout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Modifying an existing step-->
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="itemsAfter" xsi:type="array">
<item name="children" xsi:type="array">
<item name="productcheck" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
<item name="component" xsi:type="string">AquiveMedia_CustomCheckBoxesCheckout/js/view/productCheck</item>
</item>
<item name="nocancel" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
<item name="component" xsi:type="string">AquiveMedia_CustomCheckBoxesCheckout/js/view/productCheck</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
(2) app/code/vendor/module/view/frontend/web/js/view/productCheck.js
define(
[
'ko',
'uiComponent'
],
function (ko, Component)
{
"use strict";
return Component.extend({
defaults:
{
template: 'AquiveMedia_CustomCheckBoxesCheckout/nocancel'
}
});
}
);
(3) app/code/vendorname/modulename/view/frontend/web/template/productcheck.html
<div class="payment-method">
<div class="fieldset checkout-agreements">
<div class="field required checkout-agreement">
<input type="checkbox" class="required required-entry label" name="nocancel" data-validate="{required:true}" data-bind="attr: {id: 'nocancel'}"/>
<label class="label" data-bind="attr: {for: 'nocancel'}"><span data-bind="i18n: 'Custom checkbox 2'"></span></label>
</div>
</div>
</div>