Why I get this JavaScript error with jQuery Validate?
Asked Answered
S

2

12

I use jquery.unobtrusive and jquery.validate libraries in asp.net mvc 5 project to validate user registration on client side.

on browser I get this error:

Uncaught TypeError: $(...).parents(...).andSelf is not a function
    at Object.parse (jquery.validate.unobtrusive.js:211)
    at HTMLDocument.<anonymous> (jquery.validate.unobtrusive.js:392)
    at mightThrow (jquery-3.1.1.js:3570)
    at process (jquery-3.1.1.js:3638)

I use jquery 3.1.1 in my project.It seem to be versions problems.

Any idea how can I solve it?

Seemaseeming answered 29/1, 2017 at 11:48 Comment(0)
F
21

Uncaught TypeError: $(...).parents(...).andSelf is not a function

Read the jQuery docs.

"I use jquery 3.1.1 in my project."

The .andSelf() method was removed from jQuery version 3

It was an alias for the .addBack() method, which should be used instead.

Flutist answered 29/1, 2017 at 15:52 Comment(0)
C
13

Like @Sparky said, this is because the Unobtrusive JS files obtained from NuGet (if you create an app using File->New in Visual Studio) uses the deprecated andSelf() function.

To resolve, get the latest versions of

jquery.validate.unobtrusive.js jquery.validate.unobtrusive.min.js

from

https://github.com/aspnet/jquery-validation-unobtrusive/tree/master/dist

and replace the ones in your project. Or Download / Update exiting plugin from nuget.

After Replacing Make sure you clear your browser cache. (Control + F5 if you are using chrome)

Cobia answered 22/8, 2017 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.