Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
angular-async-form
Advanced tools
Async form handling the angular way.
If you've developed angular apps you know how difficult it is to handle errors after submitting a form. Common scenarios include:
Sorry, an unkown error occured. Please try again.
Angular provides a great set of directives if your only concern is immediate validation in the UI; however, they fall short for anything else.
angular-async-form
(namespaced af
) fills this gap with the following
directives:
ngSubmit
. It accepts
an angular expression (similar to ngSubmit
), and in addition to $event
it also
exposes a callback function (exposed as cb
). cb
is used to communicate with the
rest of the directives listed herein.You can customize it's behavior with afConfig.
afControlMessage
in concert with ngMessages
to display
known validation errors in the UI before submitting the form, and unkown errors
from async operations after the form is submitted.blur
event before setting it's
validity again to true
.input[type=radio]
, input[type=checkbox]
,
textara
etc.The directives are used in concert as follows:
<!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>
<!-- doSomething($event, cb) is called. It's up to doSomething to warn the
user by calling cb if errors occured in async operations. If no errors
occurred, then doSomething can do something else like hide the form and load
a new view. -->
<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>
Restriction | Requires | Scope |
---|---|---|
A | form | Parent Scope (afSubmit must equal an angular expression) |
Use afSubmit
as a direct replacement for ngSubmit
. In addition to the $event
object, a callback is exposed as cb
. cb
has the following signature:
function (message, errors)
message
- A message to display in the form E.G. Sorry, an unknown error occurred. Please try again.
. This can be a string or any data type if you
wish to display multiple form wide messages. See afMessage.
errors
- An enum of strings corresponding to control messages E.G.
{
firstName: 'First names must start with the letter J at 4\'oclock in the afternoon.',
lastName: 'We could not accept this value at this time.'
}
See afControlMessage.
Restriction | Requires | Scope |
---|---|---|
AE | ^^afSubmit | Child Scope provides message |
Adds a message to the child scope of the element it is used on. The message is
provided by passing a value as the message
parameter in the afSubmit
callback
function.
Restriction | Requires | Scope |
---|---|---|
AE | ?^^afSubmit | Parent Scope |
Groups a form control with a corresponding message. This allows error messages
passed to the errors
parameter in afSubmit
to apply to their intended
control, or group of controls in the case of radio buttons and checkboxes. Multiple afControl
s must have the same name.
Restriction | Requires | Scope |
---|---|---|
AE | ^^afControlGroup | Child Scope provides error |
Adds a message to a form control group. If the control received an error via the
errors
parameter to the callback in afSubmit
then it will be provided in this
directive's scope.
Restriction | Requires | Scope |
---|---|---|
A | ^^afControlGroup, ngModel | Parent Scope (name is a required attribute) |
Adds a form control to a form control group. The name
attribute is used as the
key when supplying errors
to the callback function in afSubmit
. This directive
may be used any number of times within afControlGroup
(I.E. with radio inputs).
If this directive does not exist within afControlGroup
, then no error will
display in afControlMessage
.
Errors must be resolved by triggering a blur event on the control; otherwise,
successive evaluations of afSubmit
will be blocked.
You can customize angular-async-form
by using afConfig
.
A simple object with the following properties:
updateOn
(defaults to blur change
) Setting this to a different DOM event changes
the event used to trigger the removal of messages displayed with afControlMessage
.The MIT License (MIT)
Copyright (c) 2015 Kogo Software LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
FAQs
Async form handling the angular way.
We found that angular-async-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.