following this post (Magento 2.2 Input field validation on Checkout page)
I can successfully add validation on the company field. But when I apply that to the region field
, it doesn't work anymore. By "doesnt work" I mean that I get no validation message at all, I can write whatever I want in the region field and I get no red message.
What I need is to validate the region field so that the user can write only 2 characters. How can I do that?
What I did:
1. created checkout_index_index.xml in my theme under app/design/frontend/Theme/default/Magento_Checkout/layout
2. Add the code specified in the post mentioned above
3. substitute "company" with "region"
Final xml:
<?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">
<!-- To affect the shipping address fields -->
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<item name="region" 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>
As I said, If I change "region" with "company", it works perfectly. But I need to apply the validation to the region field. Any idea how to achieve this?
Thanks