-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Async form validation #6416
Comments
Hmm, I'm pretty sure I saw already an issue opened for this, can't find it atm, though... |
Maybe you're thinking about my topic in angular-dev? I posted about this a I searched for it, but couldn't find it. 2014-02-23 17:54 GMT+01:00 Pawel Kozlowski [email protected]:
|
This landed in the commits in the #8267 PR. Closing. |
$asyncValidators don't solve the problem described in this issue. They only mark the input as valid/invalid but they don't modify $viewValue (example). Maybe this issue should be re-opened? |
Check out https://github.com/kogosoftwarellc/angular-async-form. I believe it solves the real issue quite nicely. The real shortcoming is that the current angular API really only handles validation up until the user submits a form. Validation errors coming back after the user submitted the form have almost been entirely ignored. That's what Here's a quick example of how it is used in a form: <!DOCTYPE html>
<html ng-app="myApp">
<head>
<style>
.error {color: red;}
</style>
</head>
<body ng-controller="AppCtrl">
<h1>Hello {{ user.firstName }}!</h1>
<form af-submit="doSomething($event, cb)" novalidate>
<div class="error" af-message>{{ message }}</div>
<div class="control-group" af-control-group>
<div class="error" af-control-message>{{ error }}</div>
<input
name="firstName"
ng-model="user.firstName"
af-control
required>
<button type="submit">Submit</button>
</div>
</form>
<script src="https://code.angularjs.org/1.4.8/angular.js"></script>
<script src="angular-async-form.js"></script>
<script src="app.js"></script>
</body>
</html> In your |
Sometimes, the client needs to communicate with the server in order to know wether the value of an input field is valid. For instance, usernames and e-mail addresses often need to be unique.
To allow this, I'd like to propose the following: When a $parsers element (from now on called a $parser, returns a value, we check wether it's a promise (both $q and native js promises). If it is, we apply a new 'processing' state to the form input. Then, then, when the resolve function is called, it receives the value you'd normally expect from a $parser.
I'm currently working on an implementation for this, but I'm new to the codebase, so it may take some time.
The text was updated successfully, but these errors were encountered: