3

I'm looking to change the generic error message in Magento 2. The default error message when an action is required is 'This is a required field'.

Example;

Configurable Product: If the add the cart button is clicked without an attribute selected, it returns the error 'This is a required field'. I'd like it to return ''Please select a {attribute_label}'. This way it will show, 'Please select a size' or 'Please select a colour'.

E-Mail Input Field: If the email signup field is left blank, and the subscribe button clicked, it returns 'This is a required field'. I'd prefer it to return 'Please enter your email'.

Please also help me understand if these error messages are called from a translation/language file, or if each field has its own error message associated with itself.

Matthew
  • 43
  • 2
  • 11
  • I'm voting to close this question as off-topic because Stack Overflow is a [programming-related](http://stackoverflow.com/help/on-topic) Q&A site. Your question is not about programming. Perhaps you should post it on http://magento.stackexchange.com instead? – Enigmativity Jun 03 '17 at 08:46

1 Answers1

0

You can see how validation is implemented for each field type in

lib/web/mage/validation.js

Validation rules applied to field are based on form configuration, for example field with 'required-entry' class will return 'This is a required field.' message as you can see in file mentioned above.

To create solution like you described you need to override default validation.js in your theme and add your own validation rules with custom messages.

Rafał Cz.
  • 735
  • 9
  • 19