3

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;
5
  • Have you try with same as shipping? Dec 7, 2016 at 9:22
  • Hi @Rakesh for Shipping Address it's working fine. Only issue with Billing Address
    – Jackson
    Dec 7, 2016 at 9:23
  • You can try with, $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payments-list']['children']['banktransfer']['children']['form-fields']['children']['street'], banktransfer-form with banktransfer only. Dec 7, 2016 at 9:42
  • Hi @Rakesh have replaced banktransfer-form with banktransfer in whole file. Seems not working & Giving Error
    – Jackson
    Dec 7, 2016 at 9:47
  • please share your error code for above code Dec 7, 2016 at 11:32

1 Answer 1

2

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.

3
  • U r Excellent @Rakesh Again. Thanks a lot :)
    – Jackson
    Dec 8, 2016 at 2:06
  • Min & Max Length Validation works fine. Have small Issue. It applies but strangely. When user on Payment Section & Change his Billing Address & Click on "Update" at that time "Street Address" validation is not executing.When i focus or click on Street Address 1 Field only, that time it's executing. On Shipping Address i'm not facing this issue. Something minor missing. Don't know. In Short It's not Executing Street Address 1 is a Required Field on load.
    – Jackson
    Dec 8, 2016 at 2:44
  • Hi @Rakesh Need ur help on this one as well if can magento.stackexchange.com/questions/147704/…
    – Jackson
    Dec 8, 2016 at 3:00

Your Answer

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

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