views:

3110

answers:

2

MicrosoftMvcJQueryValidation.js is used by ASP.NET MVC 2 for client side validation.

Having problems with this file just not working properly and wondering if I have the wrong version.

The version I am using came from the source for futures.

 MicrosoftMvcJQueryValidation.js
 5,626 bytes
 11/17/09 10:43:12am

There are two reasons i think i have the wrong version :

1) I actually have to call this code to get the validation routine working at all. This is because the default client validation function now embedded into FormContext.cs is Sys.Mvc.FormValidation.enableClientValidation .

 ViewContext.FormContext.ClientValidationFunction = "EnableClientValidation";

2) There is some code from jquery.validate.js which does the followin :

  this.settings.errorPlacement
 ? this.settings.errorPlacement(label, $(element) )
 : label.insertAfter(element);

This calls into this function in MicrosoftMvcJQueryValidation.js :

 errorPlacement: function(error, element) {
        var messageSpan = fieldToMessageMappings[element.attr("name")];
        $(messageSpan).empty();
        $(messageSpan).removeClass("field-validation-valid");
        $(messageSpan).addClass("field-validation-error");
        error.removeClass("input-validation-error");
        error.attr("_for_validation_message", messageSpan);
        error.appendTo(messageSpan);
    },

The problem is that element has been wrapped by jQuery.validate with the jQuery $(element) expression.

Therefore element.attr("name") is undefined, but element[0].attr("name") is valid.

I've taken MicrosoftMvcJQueryValidation.js from the futures download on Microsoft's site. `

I cant find any other MicrosoftMvcJQueryValidation version - but I'm sure there must be one. Can anyone help?

+5  A: 

As of Dec 17, 2009 the latest version of MicrosoftMvcJQueryValidation.js is available in the futures download project.

Be careful to include MicrosoftMvcJQueryValidation.js and NOT the similarly named MicrosoftMvcValidation.js.

Simon_Weaver
Is this code still relevant now vs2010 has shipped as futures link is dead, where will I find this js file?
tigermain
You can find it in either the "ASP.NET MVC 2 RTM Source Code" or in the "ASP.NET MVC 2 Future", both avalable at: http://aspnet.codeplex.com/releases/view/41742
Ulf Lindback
@tigermain Even though VS 2010 has shipped (for awhile at the time of this writing), what's indicated here still seems to be the right place to find MicrosoftMvcJQueryValidation.js. If I create a new project in VS for an MVC 2 (non-futures) project or even an MVC 3 Preview 1 project this file isn't in the project by default. I'm assuming if I still MVC 2 futures and created a new project it would be there, though.
Derek Morrison
A: 

I noticed that there was content missing (maybe because of conflict or error) if I added "MicrosoftMvcJQueryValidation.js". Only adding first two lines worked for me. I am using MVC RC version.

<script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript">

Any idea am I missing some functionality if I don't add that last line? Anyway, I hope this helps someone.

Tx3
We dont ask new questions in a question here @stackoverflow. It's not a forum. Create a new question if you want an answer.
jgauffin