0

I am trying to use jquery validate and I am getting the following error:

Uncaught TypeError: form.validate is not a function

Here is the order that my scripts are being referenced when I load the site since the first thing to be assumed is that I might be loading jquery after jquery-validation (but I am not):

<head>
    <script src="/lib/jquery/dist/jquery.js"></script>
    <script src="/lib/kendo-ui/js/kendo.all.min.js"></script>
    <script src="/lib/kendo-ui/js/kendo.aspnetmvc.min.js"></script>
</head>

<!-- BOTTOM OF PAGE -->
    <script src="/lib/bootstrap/dist/js/bootstrap.js"></script>
    <script src="/lib/jquery-steps/build/jquery.steps.js"></script>
    <script src="/js/site.js?v=EWaMeWsJBYWmL2g_KkgXZQ5nPe-a3Ichp0LEgzXczKo"></script>
<script src="/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

The form is declared in the html like this:

<form id="example-form" action="/MyController/Wizard" method="post">
</form>

Additionally here is my JavaScript code:

var form = $("#example-form");
form.validate({
    errorPlacement: function errorPlacement(error, element) { element.before(error); },
    rules: {
        confirm: {
            equalTo: "#password"
        }
    }
});
form.children("div").steps({
    headerTag: "h3",
    bodyTag: "section",
    transitionEffect: "slideLeft",
    onStepChanging: function (event, currentIndex, newIndex) {
        form.validate().settings.ignore = ":disabled,:hidden";
        return form.valid();
    },
    onFinishing: function (event, currentIndex) {
        form.validate().settings.ignore = ":disabled";
        return form.valid();
    },
    onFinished: function (event, currentIndex) {
        alert("Submitted!");
    }
});
Sparky
  • 98,165
  • 25
  • 199
  • 285
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
  • Are the JavaScript files loading correctly? – epascarello Feb 08 '16 at 13:58
  • Which version of jquery are you using? – mattdevio Feb 08 '16 at 13:58
  • @magreenberg jQuery 2.2.0 – Blake Rivell Feb 08 '16 at 14:01
  • @BlakeRivell If I am looking at the right documentation. It's an older plugin. Try useing jquery `v1.11.1`. – mattdevio Feb 08 '16 at 14:03
  • @magreenberg Which is an older plugin: jQuery Steps or jQuery Validate? I am assuming jQuery Steps since jQuery Validate comes with ASP.NET which comes with jQuery 2.2.0... – Blake Rivell Feb 08 '16 at 14:04
  • @BlakeRivell It will be really hard for us to help since more information is needed. Do you have a live sever you can show so we can replicate the error? – mattdevio Feb 08 '16 at 14:04
  • @magreenberg a new ASP.NET MVC6 project comes with the following 3 bower packages and versions... "jquery": "2.2.0", "jquery-validation": "1.14.0", "jquery-validation-unobtrusive": "3.2.5" I am not sure how the built in asp.net validation works if jquery validation doesn't work with jQuery 2.2.0... Unless we are talking about two different validation plugins here.. – Blake Rivell Feb 08 '16 at 14:06
  • No I do not have anything live, but if you are an asp.net person: in order to reproduce you would basically create a new ASP.NET 5 MVC application using Visual Studio 2015 and keep all of the defaults. Install jQuery Steps bower package and then try to do the Basic Form example on this site: http://www.jquery-steps.com/Examples.. I don't expect you to do all of this though I thought my issue would be something stupid/simple. Another thing I am trying to do is create a clean simple html5 site using initializr adding jQuery steps and validation to it and try to get one of those examples going. – Blake Rivell Feb 08 '16 at 14:11
  • trying move the validate plugin to the end of the `head`. – mattdevio Feb 08 '16 at 14:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102913/discussion-between-blake-rivell-and-magreenberg). – Blake Rivell Feb 08 '16 at 14:28

0 Answers0