Here’s my code that isn’t working (it’s returning true) and submits my form even with validation errors:
jQuery().ready(function() {
jQuery("#post").validate({
invalidHandler: function(form, validator) {
$("#publish").removeClass("button-primary-disabled");
$('#ajax-loading').hide();
return false;
}
});
});
This code will return false just fine and works as it should:
jQuery().ready(function() {
jQuery("#post").validate({
invalidHandler: function(form, validator) {
return false;
}
});
});
Why isn’t the first one working?
EDIT 1: Removed trailing commas, but they weren’t the problem.
EDIT 2: In case it matters, I am using this to validate a custom post type entry form in the wordpress admin. Still doesn’t explain why one works and the other doesn’t. :/
EDIT 3: It appears leaving out “return false” also works the same as leaving it in.
NEW QUESTION: How do I keep this default functionality of returning invalid (not submitting the form and returning standard error messages) but also modify my two elements?
Just by looking at your code, I do notice that there is a syntax error after your
invalidHandlerfunction: there is a trailing comma.Also, what does the form do when leaving out the
return false? I don’t see anything in the docs about that actually doing anything. By the time execution reaches this point, the submission of the form should already be cancelled.http://docs.jquery.com/Plugins/Validation/validate