Magento 2 Checkout – How to Set Max Length on Billing Address

billing-addresscheckoutcustomer-addressmagento2validation

I have achieved for Shipping Address Magento 2: How to set Max Length for Street Address?

Struggling with Billing Address on domain.com/checkout/#payment

My Payment Method is Bank Transfer. I have tried below code, but seems not working.

magento\app\code\Custom\Checkout\Block\LayoutProcessor.php

    $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payments-list']['children']['banktransfer-form']['children']['form-fields']['children']['street'] = [
        'component' => 'Magento_Ui/js/form/components/group',
        'label' => __('Street Address'),
        'required' => true,
        'dataScope' => 'banktransfer-form.street',
        //'displayArea' => 'billing-address-form-banktransfer',
        //'deps' => 'checkoutProvider',
        //'dataScopePrefix' => 'billingAddressbanktransfer',
        'provider' => 'checkoutProvider',
        'sortOrder' => 60,
        'type' => 'group',
        'children' => [
                [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'banktransfer-form',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input'
                ],
                'dataScope' => '0',
                'provider' => 'checkoutProvider',
                'validation' => ['required-entry' => true, "min_text_len‌​gth" => 1, "max_text_length" => 50],
            ],
                [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'banktransfer-form',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input'
                ],
                'dataScope' => '1',
                'provider' => 'checkoutProvider',
                'validation' => ['required-entry' => false, "min_text_len‌​gth" => 1, "max_text_length" => 50],
            ]
        ]
    ];

//        echo "<pre>";
//        print_r($jsLayout);
//        exit;

Best Answer

You have issue regarding not getting form-fields,

So you have to just keep below code in your plugin file using if condition,

if ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children']) {
    foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
        ['payment']['children']['payments-list']['children'] as $key => $value
    ) {
        if($value['component'] == 'Magento_Checkout/js/view/billing-address') {
            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payments-list']['children']['banktransfer-form']['children']['form-fields']['children']['street'] = [ 'your customization' ]
        }
    }
}

Where your customization in above code you have to keep your code for override.