Tab validation on switching tabs with ajax validation

Tab validation on switching tabs with ajax validation

I'd like to prevent switching of tabs based on validation of the current tab contents where the validation occurs asynchronously. Here's a pared down version of my non-working example:

   
  1.  function validate() {

            var formContents = ...;
            var isValid = true;
            $.post('validate.html', formContents, function(data) {
                    if (data.errors.length > 0)
                            isValid = false;
                     ...
            });
            return isValid;
    }







    $("#tabs").tabs( { select : validate });

I get why this doesn't work. The validate function returns true every time, because the post request is asynchronous and does not complete until after isValid is returned.

I guess I could change it to always return false and somehow remember the destination tab, and then at the end of the post function I could trigger going to the destination tab. Funny how it helps to write it out, maybe I'm on my way to an answer. But still, is there a more elegant solution to this that I'm missing?