"$.validator.methods[method] is undefined"

I’ve started developing a new project and have recently been getting into ASP.NET MVC and JQuery a lot more. To make my life easier I decided to use the JQuery Validation libraries to perform my client side validation. I created a simple registration form with three fields – username, password, confirm password. The following is the code I am using:

 

image

 

The code uses a remote call to the IsLoginAvailable action of the user controller which in turn checks if the entered username has already been taken and wraps the response in a JsonResult. This appeared to work fine (validating the field when focus was lost) but upon submitting the form I received the following error:

 

"$.validator.methods[…] is undefined"

 

or

 

"$.validator.methods[method] is undefined"

 

After debugging with Firebug I found that the validation was failing on a "data" method. Looking at the code I realized I was specifying the username to pass via the data section in the remote call – this was something I picked up in the examples online and assumed I too would need to use – shame on me!

 

I removed the data section from my remote call and lo-and-behold everything worked as it should. I was surprised to see that my #username value was passed correctly to the controller action and the check was performed successfully. Better still, upon submitting the form I no longer receive the "Error: ‘$.validator.methods[…]’ is null or not an object" error...now to figure out why I would or wouldn’t need the data section!

Comments

Unknown said…
You can get the same error message if you misspell required, eg.
..
rules:{
first: "require",
last: "required",

see first.
:) happy hunting.
Anonymous said…
Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

Popular posts from this blog

Excel - Adding an existing Pivot table to the data model

Mirth

Getting Started with Mirth (Part 1)