See inline...
On Wed, Jun 20, 2012 at 2:15 PM, Dario Gieselaar
<d.gie...@gmail.com> wrote:
Hi all,
I have a very simple form: it consists of a text input element and a button. It allows the user to submit a username, which is then validated on the backend. I need to adjust the form's $invalid value based on the server's response, and then set $invalid to true as soon as the user starts typing.
I realize this is doable by calling $setValidity after injecting the specific FormController in the scope via @name, and attaching a callback (e.g. setValid) to ngChange.
Not sure I understand this...
However, this kind of feels like adding view logic to the controller, and I would prefer to keep it separate, e.g. by setting a flag in the scope and having the view respond to both a change of that property as well as ngChange by adding or removing the ng-valid or mg-invalid classes. Is this possible? What is the recommended way to deal with asynchronous form validation?
I would create a simple directive on-validate="methodOnScope". This directive would call methodOnScope (passing value and probably callbacks for setInvalid and setValid).
The method might do xhr to get validation from server and then call setValid() or setInvalid(). That sounds like pretty clean solution to me.
However I didn't try it :-D Feel free to create a plunker and let us know, if you need more help...
V.
cheers,
Dario
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/UNAQy7GSfC0J.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.