Angular form validation priority

671 views
Skip to first unread message

ivang...@gmail.com

unread,
Nov 26, 2012, 6:31:54 AM11/26/12
to ang...@googlegroups.com
Hello,

I'm trying to add a custom validator to an email input.

I want my validator to be executed after the angular email validation.

Is there a way to do this?

Thanks!

Peter Bacon Darwin

unread,
Nov 26, 2012, 6:40:26 AM11/26/12
to ang...@googlegroups.com
$parsers.push(yourValidationFunction);



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

Pawel Kozlowski

unread,
Nov 26, 2012, 6:48:49 AM11/26/12
to ang...@googlegroups.com
Yes,

You've got a full control over order of validators as AngularJS keeps
all of them in a parserrs / formatters array. So you can decide where
in the array (at which stage of the validation pipeline) your
validator should end up.

For example, let's say that you write a validator to check if an
e-mail is unique and to do so you need to contact a server. But this
should be the last stage of the validation pipeline as there is no
point calling a server if an e-mail is not valid, right?

We are using this technique in the sample AngularJS app to make sure
that the server is called as late as possible:
https://github.com/angular-app/angular-app/blob/master/client/src/app/admin/users/admin-users-edit.js#L32

Hope this helps,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

ivang...@gmail.com

unread,
Nov 26, 2012, 7:25:12 AM11/26/12
to ang...@googlegroups.com
Thank you both.

Actually, the use case you just described is what I was trying to do :)
Reply all
Reply to author
Forward
0 new messages