Skip to content

Commit 6303fbc

Browse files
committed
⚡️Initial commit
0 parents  commit 6303fbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5316
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false

.github/ISSUE_TEMPLATE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Please make sure you're using the latest version before submitting an issue! -->
2+
3+
**Is this a feature request or a bug report?**
4+
<!-- GitHub issues aren't the place for questions unfortunately - please only submit feature requests or bugs! -->
5+
6+
**What's gone wrong?**
7+
<!-- Please list what has gone wrong here - for a bug please give as much information as you can so it can be reproduced, for a feature request please let us know what you are trying to achieve -->
8+
9+
**What was meant to happen?**
10+
<!-- What was actually meant to happen? Let us know what you were trying to do in the first place -->
11+
12+
**Other information**
13+
<!-- Please give as much information as you can - if you were using the CLI or node API, what OS/environment, etc, etc -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- Nice one! You're submitting a pull request. Please give us as much information as possible to help get it merged quicker! -->
2+
3+
**What are you adding/fixing?**
4+
<!-- For example, you might be fixing a bug, adding a new feature or refactoring some code. Please link to the relevant issue here as well! -->
5+
6+
**Have you added tests for your changes?**
7+
<!-- Adding tests is greatly appreciated! For all new features, tests are required. -->
8+
9+
**Will this need documentation changes?**
10+
<!-- If yes, docs will need to be changed (not necessarily by you!) before this can get merged. If you've changed the docs (you're awesome), say so here. If not (don't worry, you're still awesome), feel free to submit your PR still and someone will come along and write them up -->
11+
12+
**Does this introduce a breaking change?**
13+
<!-- If your change make a breaking change, please include as much information as possible and the reasoning behind the changes -->
14+
15+
**Other information**

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Project
2+
.idea
3+
.vscode
4+
5+
# Node
6+
node_modules
7+
8+
# macOS
9+
.DS_Store
10+
.AppleDouble
11+
.LSOverride
12+
Icon
13+
._*
14+
.Spotlight-V100
15+
.Trashes
16+
17+
## Windows
18+
Thumbs.db
19+
ehthumbs.db
20+
Desktop.ini
21+
$RECYCLE.BIN/
22+
23+
# Package Managers
24+
yarn-error.log
25+
npm-debug.log
26+
27+
# Build
28+
dist
29+
30+
# Docs
31+
gh-pages

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Contributing to @ultimate/ngerrors
2+
3+
All contributions are greatly appreciated.
4+
5+
Please make sure that any contribution you make has an issue for it, and that you link to the issue in your pull request. Before the pull request is merged the issue must have an approved label on it (this will be added if it's an approved feature/fix etc and needs to be done).
6+
7+
# Submitting an issue
8+
9+
When you submit an issue, please keep to the pre-filled template, as it will help speed things along when your issue is addressed.
10+
11+
# Make a change
12+
13+
To setup `@ultimate/ngerrors` for development, run the following -
14+
15+
```bash
16+
git clone [email protected]:UltimateAngular/ngerrors.git
17+
cd ngerrors
18+
yarn install
19+
yarn example
20+
```
21+
22+
This will start watching for changes to any source files, and compile/bundle the source.
23+
24+
You'll then need to open up the generated `dist` folder and run `yarn link`.
25+
26+
Then, inside a different project that's running webpack (for example, our `ng-boilerplate`), run:
27+
28+
```bash
29+
yarn link @ultimate/ngerrors
30+
```
31+
32+
You'll then be using your local version as the loader.
33+
34+
## Committing and adding a PR
35+
36+
Once you're ready, commit your changes and submit your PR. All commits should follow [these guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit) (to keep things neat).
37+
38+
Your PR should keep to the pre-filled template.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Ultimate Angular
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
[![Build Status][circle-badge]][circle-badge-url]
2+
[![Dependency Status][david-badge]][david-badge-url]
3+
[![devDependency Status][david-dev-badge]][david-dev-badge-url]
4+
[![npm][npm-badge]][npm-badge-url]
5+
6+
<h1 align="center">
7+
<img width="40" valign="bottom" src="https://angular.io/resources/images/logos/angular2/angular.svg">
8+
ngErrors
9+
</h1>
10+
<h4 align="center">A declarative validation module for reactive forms.</h4>
11+
12+
---
13+
14+
<a href="https://ultimateangular.com" target="_blank"><img src="https://ultimateangular.com/assets/img/banner.jpg"></a>
15+
16+
---
17+
18+
<div align="center" markdown="1">
19+
<a href="#installation">Installation</a> |
20+
<a href="#setup">Setup</a> |
21+
<a href="#documentation">Documentation</a>
22+
</div>
23+
24+
---
25+
26+
# Overview
27+
28+
Why use ngErrors, how to install and include.
29+
30+
### What is it?
31+
32+
Form validation made easy for reactive forms. Typically you'd do something like this:
33+
34+
```js
35+
<input type="text" formControlName="foo">
36+
<div *ngIf="form.get('foo').hasError('required') && form.get('foo').touched">
37+
Field is required
38+
</div>
39+
<div *ngIf="form.get('foo').hasError('minlength') && form.get('foo').dirty">
40+
Min length is 5
41+
</div>
42+
```
43+
44+
With ngErrors, we've taken a simple declarative approach that cleans up your templates:
45+
46+
```js
47+
<input type="text" formControlName="foo">
48+
<div ngErrors="foo">
49+
<div ngError="required" when="touched">
50+
Field is required
51+
</div>
52+
<div ngError="minlength" when="dirty">
53+
Min length is 5
54+
</div>
55+
</div>
56+
```
57+
58+
Check out the documentation below for all the syntax we provide.
59+
60+
### Installation
61+
62+
```bash
63+
yarn add @ultimate/ngerrors
64+
65+
# OR
66+
67+
npm i @ultimate/ngerrors
68+
```
69+
70+
### Setup
71+
72+
Just add ngErrors to your module:
73+
74+
```js
75+
import { NgErrorsModule } from '@ultimate/ngerrors';
76+
77+
@NgModule({ imports: [ NgErrorsModule ] })
78+
```
79+
80+
# Documentation
81+
82+
### ngErrors
83+
84+
The `ngErrors` directive works by dynamically fetching your FormControl under-the-hood, so simply take your `formControlName` value and pass it into `ngErrors`:
85+
86+
```html
87+
<input type="text" formControlName="username">
88+
<div ngErrors="username">
89+
// ...
90+
</div>
91+
```
92+
93+
This needs to be on a parent container that will encapsulate child `ngError` directives.
94+
95+
### ngError
96+
97+
The `ngError` directive takes either a `string` or `array` as arguments. The argument you pass in corresponds to any active errors exposed on your control, such as "required" or "minlength":
98+
99+
```html
100+
<input type="text" formControlName="username">
101+
<div ngErrors="username">
102+
<div ngError="minlength">
103+
Min length is 5
104+
</div>
105+
</div>
106+
```
107+
108+
> Note: when using array syntax, `[]` bindings are needed
109+
110+
Using an error, will show the error message when either condition are true:
111+
112+
```html
113+
<input type="text" formControlName="username">
114+
<div ngErrors="username">
115+
<div [ngError]="['minlength', 'maxlength']">
116+
Min length is 5, max length is 10
117+
</div>
118+
</div>
119+
```
120+
121+
### ngError#when
122+
123+
The `when` directive takes either a `string` or `array` as arguments. It allows you to specify when you wish to display the error based on the control state, such as "dirty" or "touched":
124+
125+
```html
126+
<input type="text" formControlName="username">
127+
<div ngErrors="username">
128+
<div ngError="minlength" when="dirty">
129+
Min length is 5
130+
</div>
131+
</div>
132+
```
133+
134+
It also comes in array format for multiple rules:
135+
136+
```html
137+
<input type="text" formControlName="username">
138+
<div ngErrors="username">
139+
<div [ngError]="minlength" [when]="['dirty', 'touched']">
140+
Min length is 5
141+
</div>
142+
</div>
143+
```
144+
145+
### Dynamic errors
146+
147+
You can optionally data-bind and dynamically create validation errors with ngErrors:
148+
149+
```html
150+
<input type="text" formControlName="username">
151+
<div ngErrors="person.username">
152+
<div *ngFor="let error of errors" [ngError]="error.name" [when]="error.rules">
153+
{{ error.text }}
154+
</div>
155+
</div>
156+
```
157+
158+
With corresponding component class:
159+
160+
```js
161+
@Component({...})
162+
export class MyComponent {
163+
errors = [
164+
{ name: 'required', text: 'This field is required', rules: ['touched', 'dirty'] },
165+
{ name: 'minlength', text: 'Min length is 5', rules: ['dirty'] }
166+
];
167+
}
168+
```
169+
170+
### Nested FormGroup support
171+
172+
ngErrors also supports FormGroups with control names using dot notation:
173+
174+
```html
175+
<div formGroupName="person">
176+
<input type="text" formControlName="username">
177+
<div ngErrors="person.username">
178+
<div ngError="minlength" [when]="['dirty', 'touched']">
179+
Min length is 5
180+
</div>
181+
</div>
182+
</div>
183+
```
184+
185+
[circle-badge]: https://circleci.com/gh/UltimateAngular/ngerrors.svg?style=shield
186+
[circle-badge-url]: https://circleci.com/gh/UltimateAngular/ngerrors
187+
[david-badge]: https://david-dm.org/UltimateAngular/ngerrors.svg
188+
[david-badge-url]: https://david-dm.org/UltimateAngular/ngerrors
189+
[david-dev-badge]: https://david-dm.org/UltimateAngular/ngerrors/dev-status.svg
190+
[david-dev-badge-url]: https://david-dm.org/UltimateAngular/ngerrors?type=dev
191+
[npm-badge]: https://img.shields.io/npm/v/@ultimate/ngerrors.svg
192+
[npm-badge-url]: https://www.npmjs.com/package/@ultimate/ngerrors

circle.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/src
5+
6+
docker:
7+
- image: node:7.7
8+
9+
steps:
10+
- checkout
11+
- run: yarn install
12+
- run: yarn run test

example/app/app.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from '@angular/core';
2+
@Component({
3+
selector: 'app-root',
4+
template: `
5+
<div>
6+
<stock-inventory></stock-inventory>
7+
</div>
8+
`
9+
})
10+
export class AppComponent {}

example/app/app.module.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { StockInventoryModule } from './stock-inventory/stock-inventory.module';
5+
6+
import { AppComponent } from './app.component';
7+
8+
@NgModule({
9+
declarations: [
10+
AppComponent
11+
],
12+
imports: [
13+
BrowserModule,
14+
StockInventoryModule
15+
],
16+
bootstrap: [
17+
AppComponent
18+
]
19+
})
20+
export class AppModule {}

0 commit comments

Comments
 (0)