Created
November 10, 2009 14:43
-
-
Save mataspetrikas/230915 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// adding a remote validation customization, that allows us to submit the form even if the backend validation failed | |
var remoteFailsafe = function(url) { | |
return function(input) { | |
return { | |
url: url, | |
timeout: 10000, | |
error: function(request, status) { | |
// get the validator object | |
var validator = $(input).parents('form').data('validator'); | |
request.abort(); | |
// if request failed, try to submit anyway | |
if (status === "timeout" && validator.formSubmitted) { | |
validator.currentForm.submit(); | |
} | |
} | |
}; | |
}; | |
}; | |
// usage example | |
$("#myform").validate({ | |
rules: { | |
'myfield': { | |
required: true, | |
rangelength: [ 3,25 ], | |
remote: remoteFailsafe("/validate/myfield") | |
}, | |
'myanotherfield': { | |
required: true, | |
rangelength: [ 10,25 ], | |
remote: remoteFailsafe("/validate/myanotherfield") | |
} | |
}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment