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?
valid()Returns: Boolean Description: Checks whether the selected form is valid or whether all selected elements are valid.
jQuery validation engine is a Javascript plugin aimed at the validation of form fields in the browser (IE 6-8, Chrome, Firefox, Safari, Opera 10). The plugin provides visually appealing prompts that grab user attention on the subject matter.
jQuery Validation is a javascript based plugin that helps you implement a powerful client side validator to your form elements that validate the value ( name, email, address, etc..) your user input when submitting.
The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form. You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With