3

I'm using this jQuery validation plugin and getting the famous:

$("#Form").validate is not a function

when trying to validate in Firebug (and equivalent messages in all other browsers).

This would imply that I'm attempting to call it before both jquery-1.4.2.js and jquery.validate.js are loaded. I've used Fiddler to show these files are being requested prior to calling validate() so in the absence of a better method I can only assume these two files are completely loaded within the browser.

Is there anywhere else I should look in order to solve this? If the scripts are requested first they should be also loaded in that order? Is there a way to find out?

I'm currently of the opinion there is something else in the plugin causing this (config etc). I've searched all over but non of the solutions seem to apply to me.

Any ideas where to look?

My jQuery is:

$(document).ready(function () {
    console.log("loaded");
    $("#Form").validate({
        rules: {
            container_0$centre_0$txtFirstName: { required: true }
        }
    });
})

and the form is:

<form method="post" action="/url" id="Form" enctype="multipart/form-data">

 <div class="ctrlholder">
    <label for="firstname">First Name</label>
    <input name="container_0$centre_0$txtFirstName" type="text" id="txtFirstName" class="required" /><em>*</em>
    <div id="errFirstName" class="error" style="display:none;">Please enter your first name</div>
  </div>
</form>

There are simplified versions of the code.

11
  • 1
    I suggest start with a blank page and start adding things until you see this problem. Commented Jul 28, 2011 at 16:25
  • Also make sure $ is actually jQuery object. Commented Jul 28, 2011 at 16:26
  • @m.edmondson: Why are you using jquery-1.4.2? The current release is 1.6.2! Commented Jul 28, 2011 at 16:28
  • @Amir - How do I check this? - This is what is implemented elsewhere I'm trying to fit it in (validate works elsewhere on the site) Commented Jul 28, 2011 at 16:30
  • 2
    are you loading any other scripts that could cause conflict? Commented Jul 28, 2011 at 16:34

3 Answers 3

1

I don't see that .validate() is a method of jQuery by itself. It looks like it's a method of a validation plug-in. I'd suggest making sure that that plug-in is properly included/installed and when working with plug-ins, you should make sure you're using a compatible version of jQuery too.

You can see from this jsFiddle that there is no property validate on a jQuery object with just jQuery included.

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

1 Comment

No - but if I add the library you'll see it works (check the jsFiddle again)
1

It appears that jquery.tools.min.js (which appears to be this) was causing the problem. On removing this I can validate as usual.

I would investigate further but I only have the minified version of the script although I'd hazard a guess it's because it has its own validation, likely causing a method name overlap.

This will be an excellent future resource for this edge case.

1 Comment

I'm glad you posted this, as I've been wrestling with this issue for an hour and it forced me to look through what else I was calling. It turns out that I had the same problem and that another plugin wanted control over my form element.
0

I put:

$. validator.setDefaults ({
    submitHandler: function () {alert ('submitted'); } 
}); 

Instead:

jQuery.validator.setDefaults ({
    debug: true, 
    success: 'valid' 
});

And it worked for me.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.