I'm using the jQuery validation plugin. It works great, an impressive tool. A couple of the 88 fields on the form I've got need to use APIs on other websites. I already found that I can't do that directly from javascript because it violates the same origin policy. So instead, it makes $.ajax calls to my own website (which, in turn invokes the APIs through curl).
The jQuery validation plugin lets you define validation methods by calling jQuery.validator.addMethod(name, method [, message ] )
The name is a string that will be used to identify the function to be called for a particular field specified in the configuration. The method is a function definition returning a boolean, and parameters consisting of the field's current value, the DOM element for the field, and params to be passed to the method.
So in my validation method, I need to make a $ajax call, process the result, and return true or false to my caller. I don't get to tell my caller to pass me functions to call for valid or invalid, I have to return a boolean to my caller. I've read the answers to this question and others like it, and as far as I can tell, all of them involve triggering a call to another function with the result of the $.ajax() call (whether using promises or callbacks) - none of them get the result back to the caller of $.ajax(), unless you pass async: false to $.ajax(). Am I missing something? Or should I tell the maintainers of the plugin that they defined a poor interface for custom validation functions :-)?