9

I want to make the postcode filed a required filed in the checkout process. I am sure that by default, this IS required but for some reason, it isn't in my store.

I know there is entry in vendor/magento/module-checkout/view/frontend/layout/checkout_index_index.xml that makes the filed required:

<item name="postcode" xsi:type="array">
     <!-- post-code field has custom UI component -->
     <item name="component" xsi:type="string">Magento_Ui/js/form/element/post-code</item>
     <item name="validation" xsi:type="array">
     <item name="required-entry" xsi:type="string">true</item></item>
</item>

But I can't see my theme overwriting this file anywhere but just to be sure I added the original file from vendor to my theme folder. Still no luck.

How else would I debug this issue?

Running on:

  • Magento 2.1.8
  • Custom theme "Venustheme/cricket"
  • Nginx
1
  • Have you tried cache flush and static content deploy after an update that XML?
    – kunj
    Commented May 17, 2018 at 11:36

2 Answers 2

27

I found my problem...

Magento 2 has a built in feature that allows the user to specify countries for optional post code.

In that feature, you can remove validation for selected countries.

Settings can be found in: Admin Panel > Stores > Settings > Configuration > General > General > Country options > Zip/Postal Code is Optional for

You have to un-tick the "Use system value" and un-select the countries that you want the post code to be validated for.

I should have properly looked through configurations rather than jumping straight to the code... I hope someone will find this useful.

-1
<item name="required-entry" xsi:type="string">true</item>

Should be a boolean instead:

<item name="required-entry" xsi:type="boolean">true</item>

Flush cache and retry?

0

Your Answer

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

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