cancel
Showing results for 
Search instead for 
Did you mean: 

override validation rules and messages

override validation rules and messages

Hi,

 

I am trying to edit the invalid message popping up after a user enters something wrong on forms (such as putting plain text in the email box of sign-in form). After many trials and errors, I have found 3 suspicious files:

1. <magento2 directory>/lib/web/mage/validation.js

2. <magento2 directory>/ventor/magento/magento2-base/lib/web/mage/validation.js

3. <magento2 directory>/ventor/magento/module-ui/view/base/web/js/lib/validation/rules.js

 

I experimented with all 3 files and found that only changes made in /lib/web/mage/validation.js work. So I have these questions:

1. I don't want to directly edit the original validation file. How do I create my custom validation file that overrides the old one?

2. What are the other 2 validation rule files for?

 

Thanks in advance!

1 REPLY 1

Re: override validation rules and messages

Hi,

 

You might want to check out these posts. Especially the one under the title ‘How to set custom validation message?’

 

https://magento.stackexchange.com/questions/177515/magento-how-to-change-validation-custom-error-mes...

https://magento.stackexchange.com/questions/163585/magento-2-how-to-set-custom-validation-message/17...

https://stackoverflow.com/questions/44339184/magento-2-error-message-this-is-a-required-field

http://inchoo.net/magento-2/validate-custom-form-in-magento-2/

 

Does anything of this solve your problem?

 

If you feel like that, you can even a fully custom validator.

The file magento/module-ui/view/base/web/js/lib/validation/rules.js is used in UI components.

We assume you are using regular field forms. Which field exactly you intend to set custom validation for?

---------------------------------------------------------

If you've found one of our answers useful, please give 'Kudos' or 'Accept as Solution'.