0

I try to add a new checkbox for the user agreements.

The checkbox is showing in the checkout fine, but it is not required.

Whats the official way to make it required?

THEME\Magento_Checkout\layout\checkout_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
                                        <item name="additional" xsi:type="array">
                                             <item name="children" xsi:type="array">
                                                <item name="checkboxes" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="user_agreement_checkbox_container" xsi:type="array">
                                                            <item name="component" xsi:type="string">Magento_Checkout/js/view/additional/user_agreement</item>
                                                            <item name="description" xsi:type="string" translate="true">Accept User Agreement</item>
                                                            <!--<item name="dataScope" xsi:type="string">amcheckout.additional.user_agreement</item>-->
                                                            <item name="provider" xsi:type="string">checkoutProvider</item>
                                                            <item name="checked" xsi:type="boolean">false</item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

THEME/Magento_Checkout/js/view/additional/user_agreement

define([
    'jquery',
    'Magento_Ui/js/form/element/single-checkbox'
], function ($,  SingleCheckbox) {
    'use strict';

    return SingleCheckbox.extend({
        defaults: {
            valueMap: {
                'true': true,
                'false': false
            }
        }
    });
});
0

You can make any field required by add required-entry true in the layout. Like below:

<item name="required-entry" xsi:type="boolean">true</item>
1
  • Does not work, I can proceed without the checkbox getting pressed. – Black Jan 27 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.