Jquery validate uses the title
attribute as the error message. I use the title
attribute to provide user tooltips, but I don't want it to replace validation error messages.
In this complete example, I've set the Last Name field to have a title
attribute while leaving the First Name field without a title
attribute. When the form submits, the First Name field properly displays the error message - "This field is required.", while the Last Name field displays the contents of the title
attribute.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
</head>
<body>
<form method="post" id="mainform">
Last Name
<input name="LastName" type="text" required="required" title="I don't want this to appear on my form" />
<br />
First Name
<input name="FirstName" type="text" required="required" />
<br />
<input type="submit" value="Submit" />
</form>
<script>
$("#mainform").validate();
</script>
</body>
</html>
Is there a way to prevent jquery-validate from using the title
attribute as an error message?
Try this:
Working demo http://jsfiddle.net/e6ndm/
Doc: http://jqueryvalidation.org/validate#toptions
Rest should fit your need :)
$("#mainform").validate({
ignoreTitle: true
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With