Skip to content

Commit 9b39d61

Browse files
committed
Release 4.3.1
1 parent 0193928 commit 9b39d61

File tree

99 files changed

+5711
-214
lines changed

Some content is hidden

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

99 files changed

+5711
-214
lines changed

README.md

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Directives for form validation (template or model driven).
55

66
# Installation
77

8-
Will be release on npm soon.
8+
```bash
9+
npm i ng4-validators --save
10+
```
911

1012
# Validators
1113

@@ -38,7 +40,6 @@ Will be release on npm soon.
3840
- notEqual
3941
- notEqualTo
4042
- number
41-
- phone
4243
- property
4344
- range
4445
- rangeLength
@@ -71,149 +72,140 @@ export class AppModule {
7172
### rangeLength
7273

7374
```html
74-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [rangeLength]="[5, 9]"/>
75+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [rangeLength]="[5, 9]">
7576
<p *ngIf="field.errors?.rangeLength">error message</p>
7677
```
7778

7879
### min
7980

8081
```html
81-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [min]="10"/>
82+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [min]="10">
8283
<p *ngIf="field.errors?.min">error message</p>
8384
```
8485

8586
### gt
8687

8788
```html
88-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [gt]="10"/>
89+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [gt]="10">
8990
<p *ngIf="field.errors?.gt">error message</p>
9091
```
9192

9293
### gte
9394

9495
```html
95-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [gte]="10"/>
96+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [gte]="10">
9697
<p *ngIf="field.errors?.gte">error message</p>
9798
```
9899

99100
### max
100101

101102
```html
102-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [max]="20"/>
103+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [max]="20">
103104
<p *ngIf="field.errors?.max">error message</p>
104105
```
105106

106107
### lt
107108

108109
```html
109-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [lt]="20"/>
110+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [lt]="20">
110111
<p *ngIf="field.errors?.lt">error message</p>
111112
```
112113

113114
### lte
114115

115116
```html
116-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [lte]="20"/>
117+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [lte]="20">
117118
<p *ngIf="field.errors?.lte">error message</p>
118119
```
119120

120121
### range
121122

122123
```html
123-
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [range]="[10, 20]"/>
124+
<input type="number" [(ngModel)]="model.field" name="field" #field="ngModel" [range]="[10, 20]">
124125
<p *ngIf="field.errors?.range">error message</p>
125126
```
126127

127128
### digits
128129

129130
```html
130-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" digits/>
131+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" digits>
131132
<p *ngIf="field.errors?.digits">error message</p>
132133
```
133134

134135
### number
135136

136137
```html
137-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" number/>
138+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" number>
138139
<p *ngIf="field.errors?.number">error message</p>
139140
```
140141

141142
### url
142143

143144
```html
144-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" url/>
145+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" url>
145146
<p *ngIf="field.errors?.url">error message</p>
146147
```
147148

148149
### email
149150

150151
```html
151-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" email/>
152+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" email>
152153
<p *ngIf="field.errors?.email">error message</p>
153154
```
154155

155156
### date
156157

157158
```html
158-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" date/>
159+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" date>
159160
<p *ngIf="field.errors?.date">error message</p>
160161
```
161162

162163
### minDate
163164

164165
```html
165-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" minDate="2016-09-09"/>
166+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" minDate="2016-09-09">
166167
<p *ngIf="field.errors?.minDate">error message</p>
167168
```
168169

169170
### maxDate
170171

171172
```html
172-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" maxDate="2016-09-09"/>
173+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" maxDate="2016-09-09">
173174
<p *ngIf="field.errors?.maxDate">error message</p>
174175
```
175176

176177
### dateISO
177178

178179
```html
179-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" dateISO/>
180+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" dateISO>
180181
<p *ngIf="field.errors?.dateISO">error message</p>
181182
```
182183

183184
### creditCard
184185

185186
```html
186-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" creditCard/>
187+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" creditCard>
187188
<p *ngIf="field.errors?.creditCard">error message</p>
188189
```
189190

190191
### json
191192

192193
```html
193-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" json/>
194+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" json>
194195
<p *ngIf="field.errors?.json">error message</p>
195196
```
196197

197198
### base64
198199

199200
```html
200-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" base64/>
201+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" base64>
201202
<p *ngIf="field.errors?.base64">error message</p>
202203
```
203204

204-
### phone
205-
206-
```html
207-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" phone="CN"/>
208-
<p *ngIf="field.errors?.phone">error message</p>
209-
```
210-
211-
details see [libphonenumber](https://github.com/halt-hammerzeit/libphonenumber-js)
212-
213205
### uuid
214206

215207
```html
216-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [uuid]="'all'"/>
208+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [uuid]="'all'">
217209
<p *ngIf="field.errors?.uuid">error message</p>
218210
```
219211

@@ -229,35 +221,46 @@ details see [libphonenumber](https://github.com/halt-hammerzeit/libphonenumber-j
229221
### equal
230222

231223
```html
232-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [equal]="'xxx'"/>
224+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [equal]="'xxx'">
233225
<p *ngIf="field.errors?.equal">error message</p>
234226
```
235227

236228
### equal
237229

238230
```html
239-
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [notEqual]="'xxx'"/>
231+
<input type="text" [(ngModel)]="model.field" name="field" #field="ngModel" [notEqual]="'xxx'">
240232
<p *ngIf="field.errors?.notEqual">error message</p>
241233
```
242234

243235
### equalTo
244236

245237
```html
246-
<input type="password" ngModel name="password" #password="ngModel" required/>
238+
<input type="password" ngModel name="password" #password="ngModel" required>
247239
<p *ngIf="password.errors?.required">required error</p>
248-
<input type="password" ngModel name="certainPassword" #certainPassword="ngModel" [equalTo]="password"/>
240+
<input type="password" ngModel name="certainPassword" #certainPassword="ngModel" [equalTo]="password">
249241
<p *ngIf="certainPassword.errors?.equalTo">equalTo error</p>
250242
```
251243

252244
### notEqualTo
253245

254246
```html
255-
<input type="text" ngModel name="password" #password="ngModel" required/>
247+
<input type="text" ngModel name="password" #password="ngModel" required>
256248
<p *ngIf="password.errors?.required">required error</p>
257-
<input type="password" ngModel name="certainPassword" #certainPassword="ngModel" [notEqualTo]="password"/>
249+
<input type="password" ngModel name="certainPassword" #certainPassword="ngModel" [notEqualTo]="password">
258250
<p *ngIf="certainPassword.errors?.equalTo">equalTo error</p>
259251
```
260252

253+
### property
254+
```typescript
255+
public obj = { id: 1 } // OK
256+
public obj = { name: 'baguette' } // KO
257+
```
258+
259+
```html
260+
<input type="text" ngModel name="obj" #obj="ngModel" property="id">
261+
<p *ngIf="obj.errors?.property">property error</p>
262+
```
263+
261264
## Model driven
262265

263266
import `ReactiveFormsModule` in *app.module.ts*
@@ -301,7 +304,7 @@ export class AppComponent {
301304
```
302305

303306
```html
304-
<input type="text" formControlName="field"/>
307+
<input type="text" formControlName="field">
305308
<p *ngIf="demoForm.from.controls.field.errors?.rangeLength">error message</p>
306309
```
307310

@@ -407,12 +410,6 @@ new FormControl('', CustomValidators.json)
407410
new FormControl('', CustomValidators.base64)
408411
```
409412

410-
### phone
411-
412-
```typescript
413-
new FormControl('', CustomValidators.phone('zh-CN'))
414-
```
415-
416413
### uuid
417414

418415
```typescript
@@ -445,9 +442,9 @@ this.form = new FormGroup({
445442

446443
```html
447444
<form [formGroup]="form">
448-
<input type="password" formControlName="password"/>
445+
<input type="password" formControlName="password">
449446
<p *ngIf="form.controls.password.errors?.required">required error</p>
450-
<input type="password" formControlName="certainPassword"/>
447+
<input type="password" formControlName="certainPassword">
451448
<p *ngIf="form.controls.certainPassword.errors?.equalTo">equalTo error</p>
452449
</form>
453450
```
@@ -466,16 +463,16 @@ this.form = new FormGroup({
466463

467464
```html
468465
<form [formGroup]="form">
469-
<input type="password" formControlName="password"/>
466+
<input type="password" formControlName="password">
470467
<p *ngIf="form.controls.password.errors?.required">required error</p>
471-
<input type="password" formControlName="certainPassword"/>
468+
<input type="password" formControlName="certainPassword">
472469
<p *ngIf="form.controls.certainPassword.errors?.notEqualTo">notEqualTo error</p>
473470
</form>
474471
```
475472

476473
### property
477474
```typescript
478-
let obj = { id: 1 };
475+
public obj = { id: 1 };
479476

480477
this.form = new FormGroup({
481478
obj: new FormControl('', CustomValidators.property('id'))
@@ -484,11 +481,11 @@ this.form = new FormGroup({
484481

485482
```html
486483
<form [formGroup]="form">
487-
<input type="text" formControlName="obj"/>
484+
<input type="text" formControlName="obj">
488485
<p *ngIf="form.controls.obj.errors?.property">property error</p>
489486
</form>
490487
```
491488

492-
# License
493-
494-
MIT
489+
# For developpers
490+
To run the projet : `npm start`
491+
Don't forget to run `npm test` and `npm lint` before each pull request. Thanks !

dist/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2017 Ralf Saenen <ralf.saenen@gmail.com>
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

0 commit comments

Comments
 (0)