AnsweredAssumed Answered

Alfresco Share client-side synchronous Form validation

Question asked by zladuric on Jan 12, 2013
I have an Alfresco Share client-side Form in a registration scenario and I want to validate if the chosen username is taken.

Can I add a Alfresco forms validator in an asynchronous way?

So far my form goes something like this:

    this.widgets.saveForm = new Alfresco.forms.Form(this.id + "-form");
    this.widgets.saveForm.addValidation(Dom.get(this.id + "-username"), this.validateUsername, me, "blur", this.msg("validation-hint.username-taken"));
But this.validateUsername needs to make an Alfresco.util.Ajax.request to a repo-side web service which checks availability for the chosen username. So basically, by the time the response is here, my original validateUsername method is long-finished, returning false (likely).

My progress so far is to disable the submit button (that is why I am passing me to the validation handler), and have success/failure callbacks enable it if the username is fine.

What would be a decent way to make a synchronous validator?

A side question would be if there is a better way to set the scope of the validation handler to this, as opposed to passing me (this method works too, this is just to make sure I am not missing a better way).

I've posted this on SO too: http://stackoverflow.com/questions/14294604/alfresco-share-client-side-synchronous-form-validation

Outcomes