Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent jquery-validate from using the title attribute as an error message?

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?

like image 790
Carter Medlin Avatar asked Oct 21 '13 20:10

Carter Medlin


1 Answers

Try this:

Working demo http://jsfiddle.net/e6ndm/

Doc: http://jqueryvalidation.org/validate#toptions

Rest should fit your need :)

$("#mainform").validate({
    ignoreTitle: true
});
like image 98
Tats_innit Avatar answered Nov 04 '22 15:11

Tats_innit