ShaneKm
ShaneKm

Reputation: 21308

MVC unobtrusive validation with JQuery 1.9 not working

I've done all the steps as described in this post:

Unobtrusive Ajax stopped working after update jQuery to 1.9.0

and this one:

jquery.unobtrusive-ajax plugin broken when updating to Jquery 1.9.0

However I still get a warning in firebug at this line in (jquery.validate.unobtrusive.js)

 $jQval.unobtrusive.parse(document);

enter image description here

Upvotes: 1

Views: 3642

Answers (2)

vinczemarton
vinczemarton

Reputation: 8156

Your solution is not incorrect, and your fix does the job, but I think a little background information on it would not hurt.

Note that what causes the warning is the jQuery Migrate plugin.

It is for providing backward compatibility for code depending on older jQuery versions. If you do not want to be warned about deprecated features and how to update them to the current standard, you can disable the warnings with the following line of code:

jQuery.migrateMute = true;

Note that these warnings only happen with the development version of jQuery Migrate, so if you switch to the minified version of jquery migrate (jquery-migrate-1.0.0.min.js) this line is not even required.

Also note that you are using the development versions of the jquery files, in a production environment you should use the minified versions, so your fix would need to be also implemented in jquery.validate.unobtrusive.min.js.

So all in all:

  • You do not need to fix it, if you use the jQuery Migrate plugin (which you do).
  • That warning can be disabled.
  • That warning will not show up in a production environment (if the correct scripts are used).
  • Microsoft will hopefully fix it anyway in the next version of jquery.validate.unobtrusive
  • If you DO fix it, make sure you also fix it in the minified version.
  • The only benefit of fixing it will be that you can drop the jQuery Migrate plugin (which I only recommend if you are absolutely sure that there is no javascript in your app depending on legacy jQuery features).

Upvotes: 1

ShaneKm
ShaneKm

Reputation: 21308

got it working without any issues now. Please let me know if this is incorrect but from what I'm seeing it's working fine.

jquery.validate.unobtrusive.js

Line 209 from this:

        var $forms = $(selector)
            .parents("form")
            .andSelf()
            .add($(selector).find("form"))
            .filter("form");

Line 209 to this:

        var $forms = $(selector)
            .parents("form")
            .addBack()
            .add($(selector).find("form"))
            .filter("form");

Line 43:

replace = container.attr("data-valmsg-replace") && $.parseJSON(container.attr("data-valmsg-replace")) !== false;

Line 73:

replace = container.attr("data-valmsg-replace") && $.parseJSON(container.attr("data-valmsg-replace"));

Upvotes: 2

Related Questions