We are using jQuery Validate Plugin for all client side validations.
Until now, we were using default error message for all the required fields (i.e. 'This field is required'), but now we need to change it to field specific error message. For example, if user doesn't enter first name, the message should be displayed as Please enter first name and so on.
These are the possibilities we have tried:
Using HTML 5 attributes
data-rule-required="true"anddata-msg-required="Madam/sir, this field is required.". Due to some other restrictions, we have to avoid using HTML 5 attributes.Providing
messagesobject while validating form:messages: { username: {required: "Please enter Username",email: "Enter valid Email"}, password: "Please enter Password" },The disadvantage of this method is that we need to modify both html and the javascipt files and the field names must be in sync for proper functining of the plugin.
I am looking for a similar solution to that of HTML 5 attributes - where I can specify a custom attribute to my input fields, the plugin will pick up the message from that field itself. Something like this:
<input type="text" required errorMessageCustomAttr="Please enter first name" />
I have referred to relevant SO questions, but unable to find any solution. Is there any way to achieve this?
.jsfile among with corresponding HTML as a solution - then you have dug yourself into a pit difficult to get out of.. these are probably the primary solutions out there..