jQuery Validation not working
Any ideas why this code doesn't work?
var newpost_validator = {};
var editpost_validator = {};
var newupload_validator = {};
var editupload_validator = {};
var newquestion_validator = {};
var editquestion_validator = {};
var comment_validator = {};
$(function()
{
newpost_validator = $("#newpostform").validate({
rules: {
post_title: "required",
post_url: {
required: {
depends: function() {
return $('input[name=post_category]:checked').val() == '14';
}
},
url: true
},
post_code: {
required: {
depends: function() {
return $('input[name=post_category]:checked').val() == '13';
}
}
},
post_content: "required",
post_tags: "required"
},
messages: {
post_title: "Your post MUST have a title",
post_url: "Please enter a valid URL, don't forget the http://",
post_code: "Please add your code",
post_content: "Your post MUST have some content",
post_tags: "Please add some tags"
}
});
editpost_validator = $("#editpostform").validate({
rules: {
post_title: "required",
post_content: "required"
},
messages: {
post_title: "Ple开发者_如何学运维ase enter a title",
post_content: "Please enter the content"
}
});
newquestion_validator = $("#newquestionform").validate({
rules: {
post_title: "required",
post_content: "required",
post_tags: "required"
},
messages: {
post_title: "Please enter a title",
post_content: "Please enter the content",
post_tags: "Please enter some tags"
}
});
editquestion_validator = $("#editquestionform").validate({
rules: {
post_title: "required",
post_content: "required"
}, },
messages: {
post_title: "Please enter a title",
post_content: "Please enter the content"
}
});
newupload_validator = $("#newuploadform").validate({
rules: {
post_title: "required",
post_upload: {
required: true,
accept: "jpg|jpeg|gif|bmp|png"
},
post_content: "required",
post_tags: "required"
},
messages: {
post_title: "Please enter a title",
post_upload: "Please upload a valid image file",
post_content: "Please enter the content",
post_tags: "Please enter some tags"
}
});
editupload_validator = $("#edituploadform").validate({
rules: {
post_title: "required",
post_content: "required"
},
messages: {
post_title: "Please enter a title",
post_content: "Please enter the content"
}
});
comment_validator = $("#commentform").validate({
rules: {
comment: "required"
},
messages: {
comment: "Please add a comment"
}
});
});
As none of the forms are being validated :/
Thanks.
Found the bug :) seems I had done this }, },
精彩评论