Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mataspetrikas/230915 to your computer and use it in GitHub Desktop.
Save mataspetrikas/230915 to your computer and use it in GitHub Desktop.
// 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