rickharrison/validate.js — pull request #36 by kijmaster (2012-09-14 12:55:17+00:00)
Title: Enable callback function to bypass form's submit action itself

I'm not fluent in english (french) so i will try to explain why i did it so that you can apply the change if you think it's important.

In a project using backbone, backbone.marionette, handlebars, etc. i perform validation on different forms using the validate.js script (Many thanks!)
The matter is: default form's submit action is bypassed only in case of validation errors. If no errors validate.js always returns true and so applies the submit action.
For some reasons i want to not apply default submit action even if no errors occur.

First i tried to do it myself in the callback function as you did, but this doesn't work with IE 6, 7 and 8 as this browser do not pass the 'event' parameter. Therefore finally i need to do it directly in the validate.js script (as you did in case of errors by returning false)

I through the best way to quickly do it without changing original behavior of your script is to handle a boolean return from the given callback function, and directly return it without checking validation errors.

Of course so that it works and not bugs in "all" browsers this is what is done at the end of my callback function (no matter validation errors occur, so it overwrite default validate.js behavior). The boolean is returned only in if the event is not passed.

// Handle event parameter and default behavior depending on browser
// IE6/7/8 won't pass the event object so return false
// so that validate.js handles the deactivation of default submit action

if (event && event.preventDefault) {
event.preventDefault();
} else if (event && event.returnValue) {
event.returnValue = false;
} else {
return false;
}

Finally to sum up, i think that this decision to apply or not the submit action should be given to the callback function if one is passed to the script, and this make the validate.js more flexible.

Do not hesitate to give me your feedback on this and again many thanks for your work.

Cheers.