Error in jquery.validate.js in MVC 4 Project with jQuery 1.9
Asked Answered
S

7

61

I created a new ASP.Net MVC 4 project using the template in Visual Studio 2012. After upgrading to jQuery 1.9, the login functionality breaks. Specifically, I get the error

0x800a138f - JavaScript runtime error: Unable to get property 'call' of undefined or null reference

at line 1172, column 5 in jquery.validate.js

How can I fix this issue?

Smoko answered 2/2, 2013 at 5:43 Comment(1)
As per the jQuery Validate plugin developer's page, version 1.10 of the plugin has only been tested through jQuery 1.8.x.Debouchment
S
85

This issue is fixed in jQuery Validation Plugin 1.11.0pre.

Unfortunately there is currently no pre-release build on NuGet, so it is currently necessary to download jquery.validation.js directly from GitHub:

jQuery.Validation 1.11 is now available via NuGet (thanks @Simon_Weaver).

UPDATE

It looks like general support for jQuery 1.9 is in the jQuery.Validation code base but not yet released

https://github.com/jzaefferer/jquery-validation/pull/613

Smoko answered 2/2, 2013 at 5:43 Comment(14)
it is now available through Nuget - nuget.org/packages/jQuery.Validation/1.11.0 I can confirm it fixes the problemHolsworth
weird, using jquery 1.9 and jquery.validation 1.11 and still getting the smae error.Metathesis
@bbqchickenrobot: I can only verify this works with jQUery 1.8.x. jQuery 1.9 removed a number of previously depreciated methods. Many third-party libraries broke as a result.Smoko
@blazkovicz: Yes, bbqchickenrobot noted that as well. jQuery 1.9 removed a number of features that were previously depreciated. I updated my answer to indicate that they're working on 1.9 support.Smoko
This is not the right answer, as it doesn't work. Until jQuery.Validation is rewritten to support jQuery 1.9/2.0 you must include the jQuery migrate plug in. See my answer :)Salpingotomy
@Stony: How can you say that is not the right answer? It provides an accurate, correct answer to the question that was asked (which by the way was MY question, so I should know).Smoko
@EricJ. Hey Eric, it's not the right answer because it doesn't solve the problem. Because it doesn't support jQuery 1.9/2.0 yet, you must use the jQuery Migrate plug in.Salpingotomy
@Stony: I (the OP) did not ask for jQuery 2.0 support. I (the OP) did test and confirm the solution on jQuery 1.9. Not sure why you believe it does not work for 1.9. The answer solves the posted problem, not any separate problem you may have.Smoko
@EricJ. Your solution says "Fixed in 1.11 pre", "1.11 is available" and "Support for 1.9 is not released, get it from the pull request". It is unclear whether you are saying 1.11 does or does not contain the necessary support. What I suggest simply solves the problem, and does so using released software, not pre-release or unmerged software. It does not appear that the pull request you mentioned was ever merged, and there is still an outstanding 1.9 compatibility issue (that jQuery Migrate solves) which references the exact problem from your question.Salpingotomy
@Stony: I added a word to my answer to hopefully reduce the confusion you are experiencing.Smoko
thanks this works!! Unbelievable that this buggy @#%%@ is so popular: unmanagable, just wasted an entire day for this (*&&% bug.Sherikasherill
Thanks a lot , updating to latest jquery validate has solved my problem too.Heredes
Thanks very much for this information. I can attest to the fact that jQuery Validation 1.13.1 also fixes the problem. I used NuGet Package Manager to install version 1.13.1 and it got rid of the problem.Coachman
This is a problem for me because I have 1.13.1 and it has this exact issue still!!Ledge
S
37

If you install jQuery.Migrate 1.1.1 then it will work fine with jQuery.Validation 1.11, jQuery 1.9 and 2.x.

As well as doing install-package jQuery.Migrate, you must then add the JavaScript to BundleConfig.cs - I added it just after jQuery and this is what the line that registers jQuery looks like now:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
  "~/Scripts/jquery-{version}.js",           // jQuery itself
  "~/Scripts/jquery-migrate-{version}.js")); // jQuery migrate
Salpingotomy answered 6/8, 2013 at 6:5 Comment(3)
+1 I found the same problem migrating to jquery-2.0.3. This fixed it. Suprisingly jquery validate has not been fixed yet.Thalamencephalon
In my case, i had to add it to the bundle "~/bundle/jqueryval", added automatically by VisualStudio if you use an MVC Internet template. So, take note peeps out there! Happy coding.Doorsill
+1. This should be the correct answer. Just updating jQuery.validation 1.11 didn't work, but your solution worked for me.Sheliasheline
B
11

The issue is the line of code inside of the validation script

$.event.handle.call(this,e);

The problem here is with $.event.handle. Both this and e have proper values. jQuery deprecated $.event.handle in favor of jQuery.event.dispatch according to the migration script http://code.jquery.com/jquery-migrate-1.2.0.js.

Fixing these errors is as easy as simply replacing the reference to handle with dispatch.

This can be wrapped in a document.ready callback to ensure it runs after the other scripts run.

$(function(){
    jQuery.event.handle = jQuery.event.dispatch
});
Bacon answered 9/7, 2015 at 20:1 Comment(1)
I was so hoping this would work for me, but it didn't. I'm using jquery 3.1.1, jquery-ui 1.12.1, and jquery.validate 1.15.1. The problem did not appear for me until I introduced jquery-ui and used bundling.Gyral
B
8

I had the same issue, no problem in firefox but ie still gives the error. I am using jquery-2.0.0; jQuery Validation Plugin 1.11.1

I found a fix: replace

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

with

@section Scripts{
    <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryval")"></script>
}
Boser answered 20/5, 2013 at 14:21 Comment(0)
D
2

Replacing the bundles script path by the following line worked for me.

 <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryval")"></script>

I tried updating the jquery validation via Nuget, and also updated the jquery to 2.0 version, but none of those solution worked. The only one that worked fine without downloading anything Pre version was the solution proposed by Texellab

Dickens answered 9/9, 2013 at 13:7 Comment(1)
This was my second choice, but did not work for me either. :(Gyral
B
0

The underlying problem is that some methods that had been deprecated since jQuery 1.7 (when new, improved methods were added) have been removed in 1.9. jQuery Validate has, apparently, not been updated so it uses the new methods instead. I found that using the jQuery Migrate Plugin, which puts the removed methods back in, solved my problems with this.

Bawl answered 31/5, 2013 at 20:36 Comment(0)
A
0

Here's another solution:

I used MVC 3 with jQuery 1.71 and jQuery UI 1.8.20. I used the jQuery UI Tabs widget and setup each tabbed area to load a partial page that contained input fields.

Works great in Firefox v22 and Chrome v28, fails in IE10. The error I got was 'Unable to get property 'settings' of undefined or null reference'

The resolution was to go to the partial forms and comment out the following code:

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>*

It now works successfully in all browsers.

Aaberg answered 19/7, 2013 at 8:45 Comment(1)
Davidson, But i'm declaring that script in the Layout page.. How to Comment out this on my partial page??Audible

© 2022 - 2024 — McMap. All rights reserved.