Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$("form").valid() throwing error, though all files included in layout

I am getting a "Object doesn't support property or method 'valid'" error throwing at the line where I am calling the valid method for my form.

$('#NewPersonForm').valid();

I checked if any stray/missed semicolons or commas, but everything seems fine. I have included the follwing scripts in my _layout.cshtml file

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/CustomizeTelerikGridFilter.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Common.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/CustomValidator.js")" type="text/javascript"></script>

Appreciate any thoughts please.

EDIT

Complete script references did not get pasted. Also I tried the same in IE, CHROME, FF

like image 532
Ananda Sudarshan Avatar asked Jan 30 '12 08:01

Ananda Sudarshan


People also ask

How do you check whether a form is valid or not in jQuery?

$("#form_id"). valid(); Checks whether the selected form is valid or whether all selected elements are valid. validate() needs to be called on the form before checking it using this method.

How do you check if a form is validated?

Using the email type, we can check the validity of the form field with a javascript function called… checkValidity() . This function returns a true|false value. checkValidity() will look at the input type as well as if the required attribute was set and any pattern="" tag .


1 Answers

I put my money on this option:
You are referencing the JQuery scripts again in the page, thus overriding the validation plugin declared in the _layout.cshtml.

JQuery plugins extends the JQuery object, So if you reference JQuery again it overrides the "extended" JQuery object.

Check the rendered HTML, you probably have two references to JQuery library

like image 199
gdoron is supporting Monica Avatar answered Oct 23 '22 04:10

gdoron is supporting Monica