How define jQuery validate setDefaults

I have a problem with my code. I use jquery validate to validate my form. My question is how to run the setDefaults method? Because when looking at it in the debugger, I get an error like this: TypeError: jQuery.validator is undefined

jQuery.validator.setDefaults({ success : "valid" }); $("#myForm").validate({ rules : { "file1" : { required : true, extension : "slx|mdl", accept : false }, "file2" : { extension : "m", accept : false }, "file3" : { extension : "xlsx|xls", accept : false }, "file4" : { extension : "pdf", accept : false } } }); 

2 Answers

setDefaults need a variable which must be used to validate in your case validator

just assign validator var to your validate method like this

var validator = $("#myForm").validate({ rules : { "file1" : { required : true, extension : "slx|mdl", accept : false }, "file2" : { extension : "m", accept : false }, "file3" : { extension : "xlsx|xls", accept : false }, "file4" : { extension : "pdf", accept : false } } }); 

should work fine

3

Check whether you added jquery validate lib correctly:

<script src="jquery.validate.min.js" type="text/javascript"></script> 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like