Reputation: 3854
I am using jquery validation plugin to validate my form.
Now the validation can be only required and/or with digits etc.
The validation messages are written like:
messages: {
required: "Required.",
email: "Invalid email",
url: "Invalid URL."
}
What i notice is that if i write title with HTML tag and dont write the messages: during the validate like:
<input id="txtDegreeName" name="txtDegreeName" title="Please Enter Degree Name"
class="required digits" type="text" />
Then title becomes Validation message.
but this validation messages will be visible for all validation like
It will show "Please Enter Degree Name" even if digits validation failed.
Problem:
I want to write the all validation messages (required digits url for a single control) inline with HTML tag
Like:
<input id="txtDegreeName" name="txtDegreeName" title="Please Enter Degree Name"
digits="PLease enter digits" class="required digits" type="text" />
So the validation plugin shows a different error messages for what what validation failed.
Any help is appreciated.
Upvotes: 2
Views: 2819
Reputation: 30666
The plugin has an option to ignore the title
attribute, which is by default the error message used when no other message has been found:
$(...).validate({
...
ignoreTitle: true
...
});
What you could do is use the jQuery Metadata plugin.
It allows you to define the rules/messages within the class attribute in the markup itself like this:
<input ... class="{ required:true, email:true, messages: { required:'Please enter your email address', email: 'Please enter a valid email address'}}" />
Here is a demo page for the metadata.
And the documentation for the validate plugin options.
Upvotes: 7