Magento 2 – Terms and Conditions Issue

bugmagento2terms and conditions

I've added a second checkbox to terms and conditions, but that is not validating.

What I've done:

I've serached and found that, iIt was or is still an magneto2 bug, but found this: https://github.com/bka/magento2/blob/6d172c93a8deaccb0b5d1449cd3b7dc6fc9e8626/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js
I've added this code but it isn't working.

After adding the code I tried following command:

php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

It's still not working.

Can Someone help with adding exact code that I have to replace?

Thanks in advance.

Best Answer

We have face the same issue(terms and conditions not validating) in our system, and change the below mentioned code. Now working properly.

File Path:

vendor/magento/module-checkout-agreements/view/frontend/web/js/model/agreement-validator.js

Change the below code:

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
/*jshint browser:true jquery:true*/
/*global alert*/
define(
    [
        'jquery',
        'mage/validation'
    ],
    function ($) {
        'use strict';
        var checkoutConfig = window.checkoutConfig,
            agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};

        var agreementsInputPath = '.payment-method._active div.checkout-agreements input';

        return {
            /**
             * Validate checkout agreements
             *
             * @returns {boolean}
             */
            validate: function() {
                var noError = true;
                if (!agreementsConfig.isEnabled || $(agreementsInputPath).length == 0) {
                    return noError;
                }

                $('.payment-method:not(._active) div.checkout-agreements input')
                    .prop('checked', false)
                    .removeClass('mage-error')
                    .siblings('.mage-error[generated="true"]').remove();

                $(agreementsInputPath).each(function() {
                    var name = $(this).attr('name');

                    var result = $('#co-payment-form').validate({
                        errorClass: 'mage-error',
                        errorElement: 'div',
                        meta: 'validate',
                        errorPlacement: function (error, element) {
                            var errorPlacement = element;
                            if (element.is(':checkbox') || element.is(':radio')) {
                                errorPlacement = element.siblings('label').last();
                            }
                            errorPlacement.after(error);
                        }
                    }).element(agreementsInputPath + '[name="' + name + '"]');

                    if (!result) {
                        noError = false;
                    }
                });

                return noError;
            }
        }
    }
);

After changed the code you will following command:

php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento cache:flush
Related Topic