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?

Sparky
  • 98,165
  • 25
  • 199
  • 285
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • As per the [jQuery Validate plugin developer's page](http://bassistance.de/jquery-plugins/jquery-plugin-validation/), version 1.10 of the plugin has only been tested through jQuery 1.8.x. – Sparky Feb 02 '13 at 05:51

7 Answers7

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

Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • it is now available through Nuget - https://nuget.org/packages/jQuery.Validation/1.11.0 I can confirm it fixes the problem – Simon_Weaver Feb 05 '13 at 04:30
  • 9
    weird, using jquery 1.9 and jquery.validation 1.11 and still getting the smae error. – bbqchickenrobot Feb 18 '13 at 18:08
  • @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. – Eric J. Feb 18 '13 at 22:07
  • @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. – Eric J. Mar 01 '13 at 17:35
  • 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 :) – Richard Aug 06 '13 at 06:08
  • @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). – Eric J. Aug 12 '13 at 21:07
  • 5
    @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. – Richard Aug 15 '13 at 07:58
  • @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. – Eric J. Aug 16 '13 at 00:08
  • @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. – Richard Aug 16 '13 at 06:09
  • 1
    @Stony: I added a word to my answer to hopefully reduce the confusion you are experiencing. – Eric J. Aug 16 '13 at 20:32
  • thanks this works!! Unbelievable that this buggy @#%%@ is so popular: unmanagable, just wasted an entire day for this (*&&% bug. – real_yggdrasil Jan 03 '14 at 17:46
  • Thanks a lot , updating to latest jquery validate has solved my problem too. – CrazyNooB Feb 17 '14 at 11:50
  • 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. – Greg Barth Jan 21 '15 at 01:59
  • This is a problem for me because I have 1.13.1 and it has this exact issue still!! – East of Nowhere May 08 '15 at 17:45
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
Richard
  • 4,740
  • 4
  • 32
  • 39
  • +1 I found the same problem migrating to jquery-2.0.3. This fixed it. Suprisingly jquery validate has not been fixed yet. – gunnerz Oct 29 '13 at 14:23
  • 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. – Luis Hernández May 28 '15 at 03:37
  • 1
    +1. This should be the correct answer. Just updating jQuery.validation 1.11 didn't work, but your solution worked for me. – Dush Aug 03 '15 at 00:37
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
});
Travis J
  • 81,153
  • 41
  • 202
  • 273
  • 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. – clairestreb Oct 27 '16 at 14:16
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>
}
Texellab
  • 101
  • 1
  • 8
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

Javier
  • 21
  • 4
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.

Vance
  • 1
  • 1
  • 1
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.