0

I have this plugin:

    public function afterProcess(
        LayoutProcessor $subject,
        array  $jsLayout
    ) {
     ...
             if(isset(
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id']
        )){
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id']
                ['validation']['validate-vat-id'] = 1;  // this doesn't work !!!
//            ['validation']['required-entry'] = 1;   // this works!!!!
        }
     ...

and this is my mixin:

var config = {
    config: {
        mixins: {
            'Magento_SalesRule/js/view/payment/discount': {
                'Vendor_Checkout/js/view/payment/discount': true
            },
            'mage/validation': {
                'Vendor_Checkout/js/validation-vat-id-mixin': true
            }
        }
    }
};

and this is my app/code/Vendor/Checkout/view/frontend/web/js/validation-vat-id-mixin.js file:

define([
    'jquery'
], function ($) {
    "use strict";

    return function () {
        $.validator.addMethod(
            'validate-vat-id',
            function (value) {
                console.log('hello custom validation');
                // Some custom validation stuff here
                return true;
            },
            $.mage.__('Your validation error message')
        );
    }
});

I'm not sure why this is not working :) . Can you give me some ideas what to try or to check ?

Thanks

1 Answer 1

0

Create the file :

NameSpace/Module/view/frontend/layout/checkout_index_index.xml

In it, I will insert rules for validation name = 'vat_id'.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" 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="steps" xsi:type="array">
                                        <item name="children" xsi:type="array">
                                            <item name="shipping-step" xsi:type="array">
                                                <item name="children" xsi:type="array">
                                                    <item name="shippingAddress" xsi:type="array">
                                                        <item name="children" xsi:type="array">
                                                            <item name="shipping-address-fieldset" xsi:type="array">
                                                                <item name="children" xsi:type="array">
                                                                    <item name="vat_id" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="min_text_length" xsi:type="number">0</item>
                                                                            <item name="max_text_length" xsi:type="number">9</item>
                                                                            <item name="letters-only" xsi:type="boolean">true</item>
                                                                            <item name="required-entry" xsi:type="boolean">true</item>
                                                                            <item name="max-words" xsi:type="number">2</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </referenceBlock>
    </body>
</page>
1
  • Hi @Vishal , Thanks for your reply , but i don't get any validation of those , for the vat_id Commented Feb 4, 2022 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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