Jquery Validation 'validate' undefined error

0

I have an MVC page that i am trying to add validation to but i keep getting the following error:

Unhandled exception

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

Any ideas why?

My code is below.

<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script>
    $(document).ready(function () {

        $("#contact").validate({
            rules: {
                "name-contact": {
                    required: true
                }
            },
            messages: {
                "name-contact": {
                    required: "Please, enter a name"
                }
            },
            submitHandler: function (form) { // for demo
                alert('valid form submitted'); // for demo
                return false; // for demo
            }
        });

    });
</script>


<form id="contact" method="post" action="#">
    <fieldset>
        <label for="name-contact">NAME</label>
        <input type="text" class="required input-xlarge" id="name-contact"
               name="name-contact" value="" placeholder="" minlength="2" />
        <input type="submit" />
    </fieldset>
</form>
jquery
validation
asked on Stack Overflow Aug 27, 2015 by Ben

2 Answers

0

There's a good chance you're not actually importing jquery.validate.js. Are you sure it's not called jquery.validate.min.js? Are you sure you have the correct path?

answered on Stack Overflow Aug 27, 2015 by Brendan
0

I found the issue. I was including the jquery bundle on the _layout page which included the following:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

Once i removed that the validation worked properly. I am not sure why that is causing issues but removing it allows the validate to work.

answered on Stack Overflow Aug 27, 2015 by Ben

User contributions licensed under CC BY-SA 3.0