1

Working on Magento 2 checkout validation following is the code

<?php
namespace VendorName\ModuleName\Block;

class LayoutProcessor
{
     /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
     public function afterProcess(
         \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
         array  $jsLayout
     ) {
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
    ['shippingAddress']['children']['shipping-address-fieldset']['children']['street'] = [
        'component' => 'Magento_Ui/js/form/components/group',
        'label' => __('Address'),
        'required' => true,
        'dataScope' => 'shippingAddress.street',
        'provider' => 'checkoutProvider',
        'sortOrder' => 60,
        'type' => 'group',
        'children' => [
            [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input'
                ],
                'dataScope' => '0',
                'provider' => 'checkoutProvider',
                'validation' => true,
                'additionalClasses' => 'additional',
                'label' => __('Street')
            ],
            [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input'
                ],
                'dataScope' => '1',
                'provider' => 'checkoutProvider',
                'validation' => true,
                'label' => __('Number')
            ],
            [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/input'
                ],
                'dataScope' => '2',
                'provider' => 'checkoutProvider',
                'validation' => true,
                'label' => __('District')
                ]
            ]

        ];

         return $jsLayout;
     }
 }

How to change the vallidation message for the fields Please help

  • which message for which field are you looking for change? – Rakesh Jesadiya Jun 23 '17 at 10:46
  • error message in street input field – Paras Arora Jun 23 '17 at 10:50
  • what message are you looking for show in this field? – Rakesh Jesadiya Jun 23 '17 at 10:51
  • "Please enter less or equal than 30 symbol" to "30 characters max" – Paras Arora Jun 23 '17 at 10:59
0

You can change validation message via magento translations.

More information here http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/translations/xlate.html

Here is ways how to add translations:

- add new translation to theme

app/design/frontend/Vendor/theme/i18n/en_US.csv (low priority: 3)

More information here http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-create.html

- create your own language package

app/code/Vendor/MyLocale/en_US.csv (priority: 2)

More information here http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-i18n.html#config-cli-subcommands-xlate-pack

- use Inline Translation in admin (high priority: 1)

Priority defines which translation dictionary will loaded first.


JS translations stored in static files so you need to re-deploy static content. Or you can just remove js-translation.json files. In magento root folder run

find pub/static/frontend -name js-translation.json -exec rm -rf {} \;

0

You should be able to translate the error messages via i18n package. But there is a bug in Magento up to 2.1.7 at least that won't let you translate these error messages. You can read this thread for possible solutions. Although I tried all of them and for me none worked so far.

https://github.com/magento/magento2/issues/4883

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.