1

I know I can add validations in the checkout_index_index.xml like this:

<item name="validation" xsi:type="array">
    <item name="validate-jurgis" xsi:type="string">true</item>
</item>

I could just override this file from my module, but I am looking for a more flexible way to do this.

Is there a way to just "add" the validation to a checkout field without overriding the entire checkout_index_index.xml?

1

You can do it like:

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

 <?xml version="1.0"?>
   <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" 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="telephone" xsi:type="array">
                                                                           <item name="config" xsi:type="array">
                                                                               <item name="tooltip" xsi:type="array">
                                                                                   <item name="description" xsi:type="string" translate="true">For delivery questions.</item>
                                                                               </item>
                                                                           </item>
                                                                           <item name="validation" xsi:type="array">
                                                                              <item name="your-validation" xsi:type="string">true</item>
                                                                          </item>
                                                                   </item>
                                                               </item>
                                                           </item>
                                                       </item>
                                                   </item>
                                               </item>
                                           </item>
                                       </item>
                                   </item>
                               </item>
                           </item>
                       </item>
                   </argument>
               </arguments>
           </referenceBlock>
       </body>
   </page>

In this example, you add it to the telephone field, but I'm sure you can see the pattern.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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