Forked from mataspetrikas/Failsafe remote validation with jquery.validate
Created
November 10, 2009 15:16
-
-
Save jzaefferer/230952 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 | |
function remoteFailsafe(url) { | |
return function(input) { | |
return { | |
url: url, | |
timeout: 10000, | |
error: function(request, status) { | |
request.abort(); | |
// if request failed, try to submit anyway | |
if (status === "timeout" && validator.formSubmitted) { | |
validator.currentForm.submit(); | |
} | |
} | |
}; | |
}; | |
}; | |
// usage example | |
var validator = $("#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