[jQuery] [validate] problem of defining custom rules
i played with the example.html from jquery.validate 1.55 and wanted to
make a custom rule firstname that is required, with the message please
enter a firstname.
My changes were in the validate :
$("#commentForm").validate({
rules: {
firstname: "required"
},
messages: {
firstname: "Enter your firstname"
}
});
and then <input id="cname" name="name" class="firstname"
minlength="2" />
my problem is that it is shown as valid, even i don't enter nothing.
i don't know what i am making wrong
Thanks,
David
This is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
<title>jQuery validation plug-in - comment form example</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/
screen.css" />
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.validate.js" type="text/javascript"></script>
<!-- for styling the form -->
<script src="js/cmxforms.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#commentForm").validate({
rules: {
firstname: "required"
},
messages: {
firstname: "Enter your firstname"
}
});
});
</script>
<style type="text/css">
#commentForm { width: 500px; }
#commentForm label { width: 250px; }
#commentForm label.error, #commentForm input.submit { margin-left:
253px; }
</style>
</head>
<body>
<form class="cmxform" id="commentForm" method="post" action="">
<fieldset>
<legend>Please provide your name, email address (won't be published)
and a comment</legend>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" class="firstname" minlength="2" />
<label for="cemail">E-Mail (required)</label>
<input id="cemail" name="email" class="required email" />
<label for="curl">URL (optional)</label>
<input id="curl" name="url" class="url" value="" />
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" class="required"></textarea>
<input class="submit" type="submit" value="Submit"/>
</fieldset>
</form>
</body>
</html>