2

I am working on top of the sample MVC4 template to build a wizard form, I have taken the source from http://afana.me/post/create-wizard-in-aspnet-mvc-3.aspx

When I trigger the java script that makes the 'next' button i get below error

var validator = $('form').validate(); // obtain validator Uncaught TypeError: Object [object Object] has no method 'validate'

Below is complete JS portion trigger with the next button.

 $("#next-step").click(function () {
        var $step = $(".wizard-step:visible"); // get current step
        var validator = $('form').validate(); // obtain validator
        var anyError = false;
        $step.find("input").each(function () {
            if (!validator.element(this)) { // validate every input element inside this step
                anyError = true;
            }
        });

        if (anyError)
            return false; // exit if any error found

I have included the library sources in the mvc4 bundles. I am able to get the client side validation successfully using unobtrusive js. But invoking the validation on next button fails.

Any help on how to fix this would be very helpful

2 Answers 2

4

I was able to figure out the problem.
The MVC4 template had a js reference at the end of the body tag.

@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)

This overrides every other jquery library and hence the method x not found.

Sign up to request clarification or add additional context in comments.

Comments

0

UPDATE ONE YEAR LATER

To elaborate, VS 2013 using MVC4 adds to the _Layout partial view

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

a redundant second time after

@Scripts.Render("~/bundles/jqueryval") has been declared

So the redeclaration of @Scripts.Render("~/bundles/jquery") at the bottom will disable useful methods as .valid() in the jqueryval bundle.

Remove it to fix.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.