1

I am looking for validate the city field in checkout page. The validation rules are city name must be chennai.

I follow this

I have add below lines in <magento-root>/vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js :

"chennai_text_value": [
        function (value, params) {
            return value != params;
        },
        $.mage.__('This product only applicable for chennai people')
 ],

I have add below lines in <magento-root>/vendor/magento/module-checkout/view/frontend/layout/checkout_index_index.xml after company field validation(name="company" find in layout for easy understand)

<item name="city" xsi:type="array">
    <item name="validation" xsi:type="array">
        <item name="chennai_text_value" xsi:type="string">chennai</item>
    </item>
</item>

but nothing can happen, I expect chennai only accept in city field.

any help?

1

problem got solved after changing condition in rules.js (value == params)

"chennai_text_value": [
    function (value, params) {
        return value == params;
    },
    $.mage.__('This product only applicable for chennai people')
 ],

note: its not a good practice to change magento core file

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.