views:

16

answers:

1

hey guys

I got ASP.NET MVC 2 running and I'd like to check for the existence of a client (basically a front-end user) via validation. To do that server side is obviously pretty easy, but I have some trouble getting it to work client side, since I somehow have to wait for the callback function inside the function which gets returned by the Sys.Mvc.ValidatorRegistry.validators - function. Some functions here, eh? ;-)

The thing looks like this:

Sys.Mvc.ValidatorRegistry.validators["uniqueuser"] = function (rule) {

    // we return the function that actually does the validation 
    return function (value, context) {
        $.getJSON('ClientExists', { email: value }, function (data) {
            if(!data.clientExists) return true;
        });
        return rule.ErrorMessage;
    };
};

Of course: if(!data.clientExists) return true; doesn't work, since the callback function is async.

How can I achieve waiting for the data to get back?

Thanks in advance.

+1  A: 

You may checkout this blog post which contains a neat example of what you are trying to do.

Darin Dimitrov
Guess I missed that one on google ;-) Thanks mate!
Dänu