2

I have bundled jquery Validate scripts like :

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.unobtrusive*",
                        "~/Scripts/jquery.validate*"));

and am rendering in the _Layout as

@Scripts.Render("~/bundles/jqueryval")

But when i try to Validate my form on button click like :

$("form").validate({
                    errorPlacement: function (error, element) {
                        error.insertAfter(element).css("display", "inline");
                    }
                });

Its giving me the error like :

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'validate'

So anyone suggest me for this problem.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Basavaraj Badiger
  • 269
  • 2
  • 9
  • 21
  • are you sure the files do show up in the source code? u sure you reference the jquery.{version}.js file? – Dejan.S Jul 03 '13 at 19:23
  • 1
    JqueryVal depends on Jquery! Are you including this before the JqueryVal? – Fals Jul 05 '13 at 19:09
  • 1
    first try `@Scripts.Render("~/bundles/jquery")` and then try to inlcude this `@Scripts.Render("~/bundles/jqueryval")` – Idrees Khan Jul 05 '13 at 19:34

2 Answers2

3

Could you make sure UnobtrusiveJavaScriptEnabled is enabled in web.config?

  <appSettings>
    ...
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    ...
  </appSettings>
Win
  • 61,100
  • 13
  • 102
  • 181
2

The runtime deferentiating minified versions from un-minified(based on standard JavaScript naming conventions), so if you specify "~/Scripts/jquery.unobtrusive*" path the specifier will include jquery.unobtrusive.js when minification turned off and jquery.unobtrusive.min.js when minification turned on.

Check out if you have jquery.unobtrusive.min.js and jquery.validate.min.js files in your Scripts folder.

To turn on minification manually - paste BundleTable.EnableOptimizations = true; after adding your bundles.

EDIT:

Your error saying that validate method didn't declared yet. Please check out if your @Scripts.Render("~/bundles/jqueryval") is located before you call $("form").validate() or wrap calling of validate into jQuery(callback) function like this:

$(function(){
    $("form").validate({
                    errorPlacement: function (error, element) {
                        error.insertAfter(element).css("display", "inline");
                    }
                });
})

That's will wait until all document is loaded.

Oleksii Aza
  • 5,368
  • 28
  • 35