I think he wants a call back to be passed so that validation can be
asynchronous. I was actually thinking about this myself before but I am not
entirely sure this is possible because AngularJS validation is synchronous
so by that time you won't be in the same phase of validation.

I suppose you could return false until the Ajax completes and then set
valid to true. But you could also just write validation the native way too.
On Nov 4, 2012 1:10 PM, "Pete Bacon Darwin" notifications@github.com
wrote:

@petebacondarwin@ProLoser Yeh, I was toying with the idea as well (I think I've even sent a PR or sth on the mailing list, don't remember really...).

I guess the use case is validation hitting the server.

I think it could be possible to support promises if we accept the fact that we would initially set the field as invalid and then set the real validation result only when a promise is resolved. The real trouble is the sync nature of AngularJS validators...

Yes, in which case this just might not be in scope which is okay too. I
think doing invalid first and valid second might very well be a decent
solution. If people want something more robust nothing stops them from
doing native validation.

We could just provide some $callback that people could execute to change
the valid state.
On Nov 4, 2012 1:22 PM, "Pawel Kozlowski" notifications@github.com wrote:

I think it could be possible to support promises if we accept the fact
that we would initially set the field as invalid and then set the real
validation result only when a promise is resolved. The real trouble is the
sync nature of AngularJS validators...

—
Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/angular-ui/issues/257#issuecomment-10055599.

You can't set the field to invalid as you get a horrible wobble of unwanted
error message while you wait for the server to decide that the thing you
entered is perfectly valid. Not nice from a user experience point of view.

What you need to do is just pass (i.e. return the value and don't call
$setValidity at all) until the async returns (possibly setting up a spinner
animation to let the user know that you are waiting for a response) you can
then call $setValidity once the server returns.

But anyway, how is this to be handled by the validate directive? Is it
that we check to see if the the validation function returns a promise and
act accordingly?

Yes, in which case this just might not be in scope which is okay too. I
think doing invalid first and valid second might very well be a decent
solution. If people want something more robust nothing stops them from
doing native validation.

We could just provide some $callback that people could execute to change
the valid state.
On Nov 4, 2012 1:22 PM, "Pawel Kozlowski" notifications@github.com
wrote:

I think it could be possible to support promises if we accept the fact
that we would initially set the field as invalid and then set the real
validation result only when a promise is resolved. The real trouble is
the
sync nature of AngularJS validators...

You can't set the field to invalid as you get a horrible wobble of
unwanted
error message while you wait for the server to decide that the thing you
entered is perfectly valid. Not nice from a user experience point of view.

What you need to do is just pass (i.e. return the value and don't call
$setValidity at all) until the async returns (possibly setting up a
spinner
animation to let the user know that you are waiting for a response) you
can
then call $setValidity once the server returns.

But anyway, how is this to be handled by the validate directive? Is it
that we check to see if the the validation function returns a promise and
act accordingly?

Yes, in which case this just might not be in scope which is okay too. I
think doing invalid first and valid second might very well be a decent
solution. If people want something more robust nothing stops them from
doing native validation.

We could just provide some $callback that people could execute to change
the valid state.
On Nov 4, 2012 1:22 PM, "Pawel Kozlowski" notifications@github.com
wrote:

I think it could be possible to support promises if we accept the fact
that we would initially set the field as invalid and then set the real
validation result only when a promise is resolved. The real trouble is
the
sync nature of AngularJS validators...

@petebacondarwin we don't need to explicitly check for promises, we can simply wrap whatever comes out of a function in $q.when and register .then callback on it. I believe that this is what is done on routes matching (and possibly in other places in AngularJS as well).

Now, the only thing that we need to check if things will work correctly if we don't return any value from a validator function. I thought that this is what AngularJS is using to set model / view value. But sure, we could always set it "by hand".

@petebacondarwinhttps://github.com/petebacondarwin we don't need to
explicitly check for promises, we can simply wrap whatever comes out of a
function in $q.when and register .then callback on it. I believe that
this is what is done on routes matching (and possibly in other places in
AngularJS as well).

Now, the only thing that we need to check if things will work correctly if
we don't return any value from a validator function. I thought that this is
what AngularJS is using to set model / view value. But sure, we could
always set it "by hand".

—
Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/angular-ui/issues/257#issuecomment-10055817.

@petebacondarwinhttps://github.com/petebacondarwin we don't need to
explicitly check for promises, we can simply wrap whatever comes out of
a
function in $q.when and register .then callback on it. I believe that
this is what is done on routes matching (and possibly in other places in
AngularJS as well).

Now, the only thing that we need to check if things will work correctly
if
we don't return any value from a validator function. I thought that this
is
what AngularJS is using to set model / view value. But sure, we could
always set it "by hand".