0

I am trying to apply a street address validation from the checkout.

In my checkout_index_index.xml file, I've added this:

<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="street" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="0" xsi:type="array">
                                                                    <item name="validation" xsi:type="array">
                                                                        <item name="maximum-length" xsi:type="string">50</item>
                                                                    </item>
                                                                </item>
                                                                <item name="1" xsi:type="array">
                                                                    <item name="validation" xsi:type="array">
                                                                        <item name="maximum-length" xsi:type="string">20</item>
                                                                    </item>
                                                                </item>
                                                                <item name="2" xsi:type="array">
                                                                    <item name="validation" xsi:type="array">
                                                                        <item name="maximum-length" xsi:type="string">10</item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </item>
            </item>
        </argument>
    </arguments>
</referenceBlock>

I am trying to add a max length for the street address fields (0,1,2). I've read this post:Magento 2 How to add validation to "street" in checkout address form? , but I don't want to create a new module for this, I am trying to fix this via the layout xml file. Can you suggest please, what I did wrong ? Any advice are welcome! :)

Thank you

[UPDATE] I also tried this one, but doesn't work:

<item name="shipping-address-fieldset" xsi:type="array">
    <item name="children" xsi:type="array">
        <item name="street" xsi:type="array">
            <item name="children" xsi:type="array">
                <item name="0" xsi:type="array">
                    <item name="validation" xsi:type="array">
                        <item name="maximum-length" xsi:type="number">50</item>
                    </item>
                </item>
                <item name="1" xsi:type="array">
                    <item name="validation" xsi:type="array">
                        <item name="maximum-length" xsi:type="number">20</item>
                    </item>
                </item>
                <item name="2" xsi:type="array">
                    <item name="validation" xsi:type="array">
                        <item name="maximum-length" xsi:type="number">10</item>
                    </item>
                </item>
            </item>
        </item>
    </item>
</item>

1 Answer 1

0

This can be fixed by updating the admin configuration

Stores -> Configuration -> Attributes -> Customer Address -> Street

Update config here:

1
  • For whatever daft reason Magento decided, this is only available for the $30K+/yr EE. Why remove a very basic feature like this from OS? Dec 7, 2022 at 16:15

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.