Created
May 29, 2013 09:59
-
-
Save danielgreen/5669244 to your computer and use it in GitHub Desktop.
This is an amended fragment of jquery.validate.js (https://github.com/jzaefferer/jquery-validation). The change is to take the value returned from validator.settings.submitHandler.call, and return that value from the handle function. This means that a page that uses submitHandler to take some action upon a successful validation can simply return…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// validate the form on submit | |
this.submit( function( event ) { | |
if ( validator.settings.debug ) { | |
// prevent form submit to be able to see console output | |
event.preventDefault(); | |
} | |
function handle() { | |
var hidden; | |
if ( validator.settings.submitHandler ) { | |
if (validator.submitButton) { | |
// insert a hidden input as a replacement for the missing submit button | |
hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm); | |
} | |
var doSubmit = validator.settings.submitHandler.call( validator, validator.currentForm, event ); | |
if (validator.submitButton) { | |
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced | |
hidden.remove(); | |
} | |
// Return the result of submitHandler instead of always returning false | |
// Means that the presence of submitHandler does not have to block propagation of the submit event | |
return doSubmit; | |
} | |
return true; | |
} | |
// prevent submit for invalid forms or custom submit handlers | |
if ( validator.cancelSubmit ) { | |
validator.cancelSubmit = false; | |
return handle(); | |
} | |
if ( validator.form() ) { | |
if ( validator.pendingRequest ) { | |
validator.formSubmitted = true; | |
return false; | |
} | |
return handle(); | |
} else { | |
validator.focusInvalid(); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment