Here is html code for the form:
The same issue showed up for me. The reason for that error what that I was using the code:
if ($("#invalidFormId").valid()) {
....
}
And the id
of the form
element was not valid
The plugin comes in separate libraries, you need to include those in your html.
<script src="../jquery-validation/dist/jquery-validate.min.js"></script>
<script src="../jquery-validation/dist/additional-methods.min.js"></script>
You need to include the validation script in the head of your document.
Like this:
<script src="/js/libs/jquery.validate.js" type="text/javascript"></script>
Also, please check in the rendered HTML that your form ID is correct.
I use this code for calling validate on my sites
//Validate Form
var ids = [];
$("form").each(function () {
ids.push(this.id);
});
var formId = "#" + ids[0]
$(formId).validate();
In my case the error was because the validator was being called too early. I moved the code to a seperate function and called it using delay method of underscore.js. Worked like a charm.
_.delay(doValidations);
function doValidations() {
...
});
I had @Scripts.Render("~/bundles/jquery")
in the parent view (_Layout.cshtml) and had also defined some other jquery Script tags in another view, they clashed.
This issue was occurring for me when calling validator.destroy() - the error was occurring within the staticRules method of the plugin. The cause turned out to be the associated form element (element.form) was detached from the DOM. I resolved it by checking the element was in the DOM before calling destroy, using the following method:
document.contains(element)
Hopefully this helps someone.