MVC2 and jquery.validate.js
- by Will I Am
I am experiencing some confusion with jquery.validate.js
First of all, what is MicrosoftMvcJqueryValidation.js. It is referenced in snippets on the web but appears to have dissapeared from the RTM MVC2 and is now in futures. Do I need it?
The reason I'm asking is that I'm trying to use the validator with MVC and I can't get it to work. I defined my JS as:
$(document).ready(function () {
$("#myForm").validate({
rules: {
f_fullname: { required: true },
f_email: { required: true, email: true },
f_email_c: { equalTo: "#f_email" },
f_password: { required: true, minlength: 6 },
f_password_c: { equalTo: "#f_password" }
},
messages: {
f_fullname: { required: "* required" },
f_email: { required: "* required", email: "* not a valid email address" },
f_email_c: { equalTo: "* does not match the other email" },
f_password: { required: "* required", minlength: "password must be at least 6 characters long" },
f_password_c: { equalTo: "* does not match the other email" }
}
});
});
and my form on the view:
<% using (Html.BeginForm("CreateNew", "Account", FormMethod.Post, new { id = "myForm" }))
{ %>
<fieldset>
<label for="f_fullname">name:</label><input id="f_fullname"/>
<label for="f_email"><input id="f_email"/>
...etc...
<input type="submit" value="Create" id="f_submit"/>
</fieldset>
<% } %>
and the validation method gets called on .ready() with no errors in firebug. however when I submit the form, nothing gets validated and the form gets submitted. If I create a submitHandler() it gets called, but the plugin doesn't detect any validation errors (.valid() == true)
What am I missing?