0

I need to validate text fields in magento shipping address popup in checkout page.I can edit validation for other forms locally.I tried many thing still not able to find the solutions.please send the location of file in magento folder and where to change the validation??

3
  • Which field you want to validate? Commented Apr 4, 2018 at 8:25
  • firstname,leastname -should only have letters Commented Apr 4, 2018 at 9:26
  • zipcode,phone number Commented Apr 4, 2018 at 9:26

1 Answer 1

0

You need to create a plugin that will plug on Magento\Checkout\Block\Checkout\LayoutProcessor::process() method :

public function afterProcess(LayoutProcessor $subject, array $jsLayout): array
{
    // change $jsLayout here

    return $jsLayout;
{

The data you want to change lays under components/checkout/children/steps/children/shipping-step/children/shippingAddress/children/shipping-address-fieldset path in the $jsLayout array. Each child of this fieldset is a shipping address form field. Add some validation rules there. You can follow this article for more details.
Note that you can use Magento\Framework\Stdlib\ArrayManager for easier read/write in a deeply nested array.
Also note that you can create your own validation rules, and add them in the checkout validation rules pool like described in this stackoverflow answer : Add rule to rules.js Magento2 (they also describe how to update the jsLayout data, but I think the example is a little over-complicated, that's why I gave the first link).

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.