@sbcore/ng-absolute-validator 14.0.0 → 14.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +245 -257
- package/esm2020/lib/directive/error-trigger/error-trigger-on.directive.mjs +5 -5
- package/esm2020/lib/ng-absolute-validator.module.mjs +6 -8
- package/esm2020/lib/rule/above/above.directive.mjs +6 -6
- package/esm2020/lib/rule/accepted/accepted.directive.mjs +6 -6
- package/esm2020/lib/rule/after/after.directive.mjs +6 -6
- package/esm2020/lib/rule/alpha/alpha.directive.mjs +6 -6
- package/esm2020/lib/rule/alpha_dash/alpha-dash.directive.mjs +6 -6
- package/esm2020/lib/rule/alpha_numeric/alpha-numeric.directive.mjs +6 -6
- package/esm2020/lib/rule/array/array.directive.mjs +6 -6
- package/esm2020/lib/rule/before/before.directive.mjs +6 -6
- package/esm2020/lib/rule/between/between.directive.mjs +6 -6
- package/esm2020/lib/rule/boolean/boolean.directive.mjs +6 -6
- package/esm2020/lib/rule/confirmed/confirmed.directive.mjs +6 -6
- package/esm2020/lib/rule/credit_card/credit-card.directive.mjs +6 -6
- package/esm2020/lib/rule/cvv/cvv.directive.mjs +6 -6
- package/esm2020/lib/rule/date/date.directive.mjs +6 -6
- package/esm2020/lib/rule/date_format/date-format.directive.mjs +6 -6
- package/esm2020/lib/rule/debit_card/debit-card.directive.mjs +6 -6
- package/esm2020/lib/rule/different/different.directive.mjs +6 -6
- package/esm2020/lib/rule/dimension/dimension.directive.mjs +6 -6
- package/esm2020/lib/rule/email/email.directive.mjs +6 -6
- package/esm2020/lib/rule/ends_with/ends-with.directive.mjs +6 -6
- package/esm2020/lib/rule/equals/equals.directive.mjs +6 -6
- package/esm2020/lib/rule/exists/exists.directive.mjs +6 -6
- package/esm2020/lib/rule/image/image.directive.mjs +7 -7
- package/esm2020/lib/rule/in/in.directive.mjs +6 -6
- package/esm2020/lib/rule/includes/includes.directive.mjs +6 -6
- package/esm2020/lib/rule/integer/integer.directive.mjs +6 -6
- package/esm2020/lib/rule/ip/ip.directive.mjs +6 -6
- package/esm2020/lib/rule/ipv4/ipv4.directive.mjs +6 -6
- package/esm2020/lib/rule/ipv6/ipv6.directive.mjs +6 -6
- package/esm2020/lib/rule/json/json.directive.mjs +6 -6
- package/esm2020/lib/rule/max/max.directive.mjs +6 -6
- package/esm2020/lib/rule/mimes/mimes.directive.mjs +6 -6
- package/esm2020/lib/rule/min/min.directive.mjs +6 -6
- package/esm2020/lib/rule/not_equals/not-equals.directive.mjs +7 -7
- package/esm2020/lib/rule/not_in/not-in.directive.mjs +6 -6
- package/esm2020/lib/rule/not_regex/not-regex.directive.mjs +6 -6
- package/esm2020/lib/rule/number/number.directive.mjs +6 -6
- package/esm2020/lib/rule/phone_no/phone-no.directive.mjs +7 -7
- package/esm2020/lib/rule/range/range.directive.mjs +6 -6
- package/esm2020/lib/rule/regex/regex.directive.mjs +6 -6
- package/esm2020/lib/rule/required/required.directive.mjs +6 -6
- package/esm2020/lib/rule/required_if/required-if.directive.mjs +6 -6
- package/esm2020/lib/rule/required_unless/required-unless.directive.mjs +6 -6
- package/esm2020/lib/rule/required_with/required-with.directive.mjs +6 -6
- package/esm2020/lib/rule/required_with_all/required-with-all.directive.mjs +6 -6
- package/esm2020/lib/rule/required_without/required-without.directive.mjs +6 -6
- package/esm2020/lib/rule/required_without_all/required-without-all.directive.mjs +6 -6
- package/esm2020/lib/rule/rule.directive.mjs +6 -6
- package/esm2020/lib/rule/rule.module.mjs +76 -111
- package/esm2020/lib/rule/same/same.directive.mjs +6 -6
- package/esm2020/lib/rule/size/size.directive.mjs +6 -6
- package/esm2020/lib/rule/starts_with/starts-with.directive.mjs +6 -6
- package/esm2020/lib/rule/strength/strength.directive.mjs +6 -6
- package/esm2020/lib/rule/string/string.directive.mjs +6 -6
- package/esm2020/lib/rule/under/under.directive.mjs +6 -6
- package/esm2020/lib/rule/unique/unique.directive.mjs +6 -6
- package/esm2020/lib/rule/url/url.directive.mjs +6 -6
- package/esm2020/lib/rule/uuid/uuid.directive.mjs +6 -6
- package/esm2020/lib/rule/video/video.directive.mjs +6 -6
- package/fesm2015/sbcore-ng-absolute-validator.mjs +349 -386
- package/fesm2015/sbcore-ng-absolute-validator.mjs.map +1 -1
- package/fesm2020/sbcore-ng-absolute-validator.mjs +347 -384
- package/fesm2020/sbcore-ng-absolute-validator.mjs.map +1 -1
- package/lib/common.utils.d.ts +8 -0
- package/lib/config-interface.d.ts +15 -0
- package/lib/constant.d.ts +61 -0
- package/lib/directive/error-trigger/error-trigger-on.directive.d.ts +3 -3
- package/lib/interface.d.ts +143 -0
- package/lib/ng-absolute-validator.component.d.ts +77 -0
- package/lib/ng-absolute-validator.module.d.ts +1 -1
- package/lib/ng-absolute-validator.service.d.ts +45 -0
- package/lib/rule/above/above.directive.d.ts +3 -3
- package/lib/rule/accepted/accepted.directive.d.ts +3 -3
- package/lib/rule/after/after.directive.d.ts +3 -3
- package/lib/rule/alpha/alpha.directive.d.ts +3 -3
- package/lib/rule/alpha_dash/alpha-dash.directive.d.ts +3 -3
- package/lib/rule/alpha_numeric/alpha-numeric.directive.d.ts +3 -3
- package/lib/rule/array/array.directive.d.ts +3 -3
- package/lib/rule/before/before.directive.d.ts +3 -3
- package/lib/rule/between/between.directive.d.ts +3 -3
- package/lib/rule/boolean/boolean.directive.d.ts +3 -3
- package/lib/rule/confirmed/confirmed.directive.d.ts +3 -3
- package/lib/rule/credit_card/credit-card.directive.d.ts +3 -3
- package/lib/rule/cvv/cvv.directive.d.ts +3 -3
- package/lib/rule/date/date.directive.d.ts +3 -3
- package/lib/rule/date_format/date-format.directive.d.ts +3 -3
- package/lib/rule/debit_card/debit-card.directive.d.ts +3 -3
- package/lib/rule/different/different.directive.d.ts +3 -3
- package/lib/rule/dimension/dimension.directive.d.ts +3 -3
- package/lib/rule/email/email.directive.d.ts +3 -3
- package/lib/rule/ends_with/ends-with.directive.d.ts +3 -3
- package/lib/rule/equals/equals.directive.d.ts +3 -3
- package/lib/rule/exists/exists.directive.d.ts +3 -3
- package/lib/rule/image/image.directive.d.ts +3 -3
- package/lib/rule/in/in.directive.d.ts +3 -3
- package/lib/rule/includes/includes.directive.d.ts +3 -3
- package/lib/rule/integer/integer.directive.d.ts +3 -3
- package/lib/rule/ip/ip.directive.d.ts +3 -3
- package/lib/rule/ipv4/ipv4.directive.d.ts +3 -3
- package/lib/rule/ipv6/ipv6.directive.d.ts +3 -3
- package/lib/rule/json/json.directive.d.ts +3 -3
- package/lib/rule/max/max.directive.d.ts +3 -3
- package/lib/rule/mimes/mimes.directive.d.ts +3 -3
- package/lib/rule/min/min.directive.d.ts +3 -3
- package/lib/rule/not_equals/not-equals.directive.d.ts +3 -3
- package/lib/rule/not_in/not-in.directive.d.ts +3 -3
- package/lib/rule/not_regex/not-regex.directive.d.ts +3 -3
- package/lib/rule/number/number.directive.d.ts +3 -3
- package/lib/rule/phone_no/phone-no.directive.d.ts +3 -3
- package/lib/rule/range/range.directive.d.ts +3 -3
- package/lib/rule/regex/regex.directive.d.ts +3 -3
- package/lib/rule/required/required.directive.d.ts +3 -3
- package/lib/rule/required_if/required-if.directive.d.ts +3 -3
- package/lib/rule/required_unless/required-unless.directive.d.ts +3 -3
- package/lib/rule/required_with/required-with.directive.d.ts +3 -3
- package/lib/rule/required_with_all/required-with-all.directive.d.ts +3 -3
- package/lib/rule/required_without/required-without.directive.d.ts +3 -3
- package/lib/rule/required_without_all/required-without-all.directive.d.ts +3 -3
- package/lib/rule/rule.directive.d.ts +17 -0
- package/lib/rule/rule.module.d.ts +1 -1
- package/lib/rule/same/same.directive.d.ts +3 -3
- package/lib/rule/size/size.directive.d.ts +3 -3
- package/lib/rule/starts_with/starts-with.directive.d.ts +3 -3
- package/lib/rule/strength/strength.directive.d.ts +3 -3
- package/lib/rule/string/string.directive.d.ts +3 -3
- package/lib/rule/under/under.directive.d.ts +3 -3
- package/lib/rule/unique/unique.directive.d.ts +3 -3
- package/lib/rule/url/url.directive.d.ts +3 -3
- package/lib/rule/uuid/uuid.directive.d.ts +3 -3
- package/lib/rule/video/video.directive.d.ts +3 -3
- package/lib/services/http.request.service.d.ts +11 -0
- package/lib/services/messages-builder.service.d.ts +9 -0
- package/lib/services/utils.service.d.ts +81 -0
- package/lib/services/validate-rule.service.d.ts +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,257 +1,245 @@
|
|
|
1
|
-
# Angular Absolute Validator
|
|
2
|
-
Like no other form validation library, simply write in English your requirements inside your form HTML tags, Absolute Validator will do the rest.
|
|
3
|
-
|
|
4
|
-
> **Package renamed:** this library was previously published as `ng-absolute-validator`. It now lives at **`@
|
|
5
|
-
|
|
6
|
-
## New Features
|
|
7
|
-
* Package renamed from `ng-absolute-validator` to `@
|
|
8
|
-
* New `showErrorOn` input — choose which state(s) (`touched`, `dirty`, `submit`, `always`) trigger the error display, combinable as an array.
|
|
9
|
-
* New `disableDefaultError` input — turn off the library's built-in error rendering for a field so you can build fully custom error UI off the `errorMessages` output instead.
|
|
10
|
-
* New `errorMessages` output — emits the full list of raw validation error messages for a control, not just the rendered inline message.
|
|
11
|
-
* Add error messages with multi-language support ([see below](#multi-language-error-messages)).
|
|
12
|
-
* Set a fallback language for an empty main message.
|
|
13
|
-
* Add the language and message object at the application root.
|
|
14
|
-
* Add an inline error message with multi-language support.
|
|
15
|
-
* No need to add a field name for reactive validation.
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|`
|
|
199
|
-
|`
|
|
200
|
-
|`
|
|
201
|
-
|`
|
|
202
|
-
|`
|
|
203
|
-
|`
|
|
204
|
-
|`
|
|
205
|
-
|`
|
|
206
|
-
|`
|
|
207
|
-
|`
|
|
208
|
-
|`
|
|
209
|
-
|`
|
|
210
|
-
|`
|
|
211
|
-
|`
|
|
212
|
-
|`
|
|
213
|
-
|`
|
|
214
|
-
|`
|
|
215
|
-
|`
|
|
216
|
-
|`
|
|
217
|
-
|`
|
|
218
|
-
|`
|
|
219
|
-
|`
|
|
220
|
-
|`
|
|
221
|
-
|`
|
|
222
|
-
|`
|
|
223
|
-
|`
|
|
224
|
-
|`
|
|
225
|
-
|`
|
|
226
|
-
|`
|
|
227
|
-
|`
|
|
228
|
-
|`
|
|
229
|
-
|`
|
|
230
|
-
|`
|
|
231
|
-
|`
|
|
232
|
-
|`
|
|
233
|
-
|`
|
|
234
|
-
|`
|
|
235
|
-
|`
|
|
236
|
-
|`
|
|
237
|
-
|`
|
|
238
|
-
|`
|
|
239
|
-
|`
|
|
240
|
-
|`
|
|
241
|
-
|`
|
|
242
|
-
|`
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|`size`|`size:120`|Ensures the size of the file not more than the specific size (in KB).|
|
|
247
|
-
|`startsWith`|`starts_with:a,b`|Ensures the value of 2 fields are same.|
|
|
248
|
-
|`string`|`string`|Ensures the value is a string.|
|
|
249
|
-
|`strength`|`strength`| Make sure the value strength should mach pre defined regex expression.<br><br> Add or overide with new regex expression from root config.<br> Add or modify progess bar color combination from root config.<br> <ul> <b>a</b> : String must be 8 charecter long.<br> <b>b</b> : String must contain one uppercase letter.<br> <b>c</b> : String must contain one spatial charecter.<br> <b>d</b> : String must contain one digit.<br> <b>b</b> : String must contain one lowecase letter.<br> </ul> |
|
|
250
|
-
|`under`|`under:10`|Ensures the value of a field is under a certain value. All values will be casted to Number|
|
|
251
|
-
|`url`|`url`|Ensures the value is a valid URL format.|
|
|
252
|
-
|`uuid`|`uuid`|Ensures the value is a valid UUID format.|
|
|
253
|
-
|`unique`|`rv.unique({url:'...'})`|Ensures the value is unique in the database. Only <b>GET</b> and <b>POST</b> methods are<br>allowed for remote validation; the default method is <b>GET</b>. Passed as its own call, not inside the `rule` chain.|
|
|
254
|
-
|`video`|`video`|Ensures the upload file is an valid video file|
|
|
255
|
-
|
|
256
|
-
## License
|
|
257
|
-
This project is licensed under the terms of the MIT license.
|
|
1
|
+
# Angular Absolute Validator
|
|
2
|
+
Like no other form validation library, simply write in English your requirements inside your form HTML tags, Absolute Validator will do the rest.
|
|
3
|
+
|
|
4
|
+
> **Package renamed:** this library was previously published as `ng-absolute-validator`. It now lives at **`@sbcore/ng-absolute-validator`** — update your install command and imports to the new scoped name below. The old package name is deprecated and will no longer receive updates; existing installs keep working, but new features (including everything in this release) are only published under the new name.
|
|
5
|
+
|
|
6
|
+
## New Features
|
|
7
|
+
* Package renamed from `ng-absolute-validator` to `@sbcore/ng-absolute-validator` ([see above](#angular-absolute-validator)).
|
|
8
|
+
* New `showErrorOn` input — choose which state(s) (`touched`, `dirty`, `submit`, `always`) trigger the error display, combinable as an array.
|
|
9
|
+
* New `disableDefaultError` input — turn off the library's built-in error rendering for a field so you can build fully custom error UI off the `errorMessages` output instead.
|
|
10
|
+
* New `errorMessages` output — emits the full list of raw validation error messages for a control, not just the rendered inline message.
|
|
11
|
+
* Add error messages with multi-language support ([see below](#multi-language-error-messages)).
|
|
12
|
+
* Set a fallback language for an empty main message.
|
|
13
|
+
* Add the language and message object at the application root.
|
|
14
|
+
* Add an inline error message with multi-language support.
|
|
15
|
+
* No need to add a field name for reactive validation.
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
Go to [Full Documentation](http://package.sbdeveloper.in/docs/ng-absolute-form-validator/14.0)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
To install this library, run:
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install @sbcore/ng-absolute-validator
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
> Upgrading from the old package? Uninstall the deprecated name first: `npm uninstall ng-absolute-validator`, then install `@sbcore/ng-absolute-validator` as above and update every import in your project to match (see below).
|
|
28
|
+
|
|
29
|
+
Import `FormsModule`, `ReactiveFormsModule` and `NgAbsoluteValidatorModule` in your Angular `AppModule`. `FormsModule` is required for template-driven forms, `ReactiveFormsModule` is required for reactive forms (see the examples below) — import both if your app uses either style.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
33
|
+
import { NgModule } from '@angular/core';
|
|
34
|
+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
35
|
+
import { AppComponent } from './app.component';
|
|
36
|
+
import { NgAbsoluteValidatorModule } from '@sbcore/ng-absolute-validator';
|
|
37
|
+
|
|
38
|
+
@NgModule({
|
|
39
|
+
declarations: [
|
|
40
|
+
AppComponent
|
|
41
|
+
],
|
|
42
|
+
imports: [
|
|
43
|
+
BrowserModule,
|
|
44
|
+
FormsModule,
|
|
45
|
+
ReactiveFormsModule,
|
|
46
|
+
NgAbsoluteValidatorModule.forRoot({})
|
|
47
|
+
],
|
|
48
|
+
providers: [],
|
|
49
|
+
bootstrap: [AppComponent]
|
|
50
|
+
})
|
|
51
|
+
export class AppModule { }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Multi-language Error Messages
|
|
55
|
+
|
|
56
|
+
`NgAbsoluteValidatorModule` can render validation messages in more than one language: a project-wide message set is registered once at the application root, with a fallback language for anything not translated, and any single field can override or extend that message set inline.
|
|
57
|
+
|
|
58
|
+
### Registering languages at the application root
|
|
59
|
+
|
|
60
|
+
Pass your message object and the active language to `forRoot()` when importing the module in `AppModule`:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { NgModule } from '@angular/core';
|
|
64
|
+
import { NgAbsoluteValidatorModule } from '@sbcore/ng-absolute-validator';
|
|
65
|
+
|
|
66
|
+
@NgModule({
|
|
67
|
+
imports: [
|
|
68
|
+
NgAbsoluteValidatorModule.forRoot({
|
|
69
|
+
language: 'en',
|
|
70
|
+
fallbackLanguage: 'en',
|
|
71
|
+
messages: {
|
|
72
|
+
en: {
|
|
73
|
+
required: 'The :attribute field is required.',
|
|
74
|
+
email: 'The :attribute must be a valid email address.',
|
|
75
|
+
above: 'The :attribute should be above :arg0.'
|
|
76
|
+
},
|
|
77
|
+
ar: {
|
|
78
|
+
required: 'حقل :attribute مطلوب.',
|
|
79
|
+
email: 'يجب أن يكون :attribute بريدًا إلكترونيًا صالحًا.'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
export class AppModule { }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Falling back to a default language
|
|
89
|
+
|
|
90
|
+
If the active `language` has no message defined for a rule that fails, the library looks it up in `fallbackLanguage` instead of showing a blank or missing message. In the example above, an Arabic-language user who fails the `above` rule sees the English fallback message, since the `ar` message set never defines one for `above`.
|
|
91
|
+
|
|
92
|
+
### Inline, per-field message overrides
|
|
93
|
+
|
|
94
|
+
A single field can override — or add — messages without touching the root configuration, by passing a message object as the second argument to `rv.map()`. It only affects that field:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
public aboveMessage: any = {
|
|
98
|
+
en: { above: 'The :attribute should be above :arg0.' },
|
|
99
|
+
ar: { above: 'ال :attribute يجب أن يكون أعلاه :arg0.' }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public formRules = {
|
|
103
|
+
above: ['', this.rv.map('above:20', this.aboveMessage)],
|
|
104
|
+
// ...
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use this when one field needs custom wording that shouldn't apply to every other field using the same rule elsewhere in the app.
|
|
109
|
+
|
|
110
|
+
## Add CSS Style for color effect on validation
|
|
111
|
+
Add CSS style to application style.css file to get color effect on validation.
|
|
112
|
+
|
|
113
|
+
```css
|
|
114
|
+
.ng-invalid:not(form):not(.ng-untouched){
|
|
115
|
+
border: 1px solid red;
|
|
116
|
+
}
|
|
117
|
+
.ng-valid:not(form){
|
|
118
|
+
border: 1px solid green;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
## Template driven form validation Example
|
|
122
|
+
Once your library is imported, you can use the validation display message component and directive to activate the validation process.
|
|
123
|
+
|
|
124
|
+
```html
|
|
125
|
+
<!-- For directive use, with no chain rules -->
|
|
126
|
+
<form (ngSubmit)="onSubmit(form)" #form="ngForm">
|
|
127
|
+
<input type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
|
|
128
|
+
<ng-absolute-validator [formInstance]="<name>" (onValid)="getStatus($event)"></ng-absolute-validator>
|
|
129
|
+
</form>
|
|
130
|
+
|
|
131
|
+
<!-- For Chain validation -->
|
|
132
|
+
<form (ngSubmit)="onSubmit(form)" #form="ngForm">
|
|
133
|
+
<input rule="required|integer|above:20" type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
|
|
134
|
+
<ng-absolute-validator [formInstance]="<name>" (onValid)="getStatus($event)"></ng-absolute-validator>
|
|
135
|
+
</form>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Reactive form validation Example
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Component } from '@angular/core';
|
|
142
|
+
import { ReactiveValidator } from '@sbcore/ng-absolute-validator';
|
|
143
|
+
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
144
|
+
|
|
145
|
+
@Component({
|
|
146
|
+
selector: 'app-reactive',
|
|
147
|
+
templateUrl: './reactive.component.html',
|
|
148
|
+
styleUrls: ['./reactive.component.css']
|
|
149
|
+
})
|
|
150
|
+
export class ReactiveComponent {
|
|
151
|
+
|
|
152
|
+
public form: FormGroup;
|
|
153
|
+
public formRules: { [key: string]: any };
|
|
154
|
+
|
|
155
|
+
public aboveMessage: any = {
|
|
156
|
+
en: { above: 'The :attribute should be above :arg0.' },
|
|
157
|
+
ar: { above: 'ال :attribute يجب أن يكون أعلاه :arg0.' }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
constructor(
|
|
161
|
+
private fb: FormBuilder,
|
|
162
|
+
private rv: ReactiveValidator,
|
|
163
|
+
) {
|
|
164
|
+
this.formRules = {
|
|
165
|
+
above: ['', this.rv.map('above:20', this.aboveMessage)],
|
|
166
|
+
dimension: ['',
|
|
167
|
+
this.rv.map('image'),
|
|
168
|
+
this.rv.dimension('width=200px,height=200px')
|
|
169
|
+
],
|
|
170
|
+
email: ['',
|
|
171
|
+
this.rv.map('email'),
|
|
172
|
+
this.rv.unique({ url: 'http://jsonplaceholder.typicode.com/users' })
|
|
173
|
+
],
|
|
174
|
+
}
|
|
175
|
+
this.form = this.fb.group(this.formRules);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
## Validation Rules
|
|
180
|
+
All validation rules and error message details are given in the documentation: [Full Documentation](http://package.sbdeveloper.in/docs/ng-absolute-form-validator/14.0)
|
|
181
|
+
|
|
182
|
+
The **Rule** column is the name used in code (e.g. as a `RuleValidatorsService` method); the **Usage** column is the exact string you write inside `rule="..."` or `rv.map('...')` — note that multi-word rules use `snake_case` there, not camelCase.
|
|
183
|
+
|
|
184
|
+
| Rules | Usage | Description |
|
|
185
|
+
| :--- | :--- | :--- |
|
|
186
|
+
|`above`|`above:20`|Makes sure the value provided by the end user is above the expected value. This method will wrap<br>both the values|
|
|
187
|
+
|`accepted`|`accepted`|Ensures that the field under validation is accepted. Empty strings, false, null, 0 and undefined<br>values will be considered as not accepted.|
|
|
188
|
+
|`after`|`after:12-01-1991`|Ensures the value of the field is after the expected date.|
|
|
189
|
+
|`alpha`|`alpha`|Makes sure the field under validation is alpha only.|
|
|
190
|
+
|`alphaDash`|`alpha_dash`|Makes sure the field under validation is contain letters, numbers, dashes and underscores.|
|
|
191
|
+
|`alphaNumeric`|`alpha_numeric`|Makes sure the field under validation is alpha numeric only.|
|
|
192
|
+
|`array`|`array`|Ensure the value is a valid array. Also this validation will never validate the size of array.|
|
|
193
|
+
|`before`|`before:12-01-1991`|Ensures the value of field under validation is before a given date.|
|
|
194
|
+
|`between`|`between:5,10`|Ensures a numeric value falls strictly between the two given bounds, exclusive of both endpoints<br>(so `between:5,10` accepts 6-9 but rejects 5 and 10). Unlike `range`, the boundary values themselves<br>are not accepted.|
|
|
195
|
+
|`boolean`|`boolean`|Ensures the value of a field is a boolean. Also it will cast following strings to their boolean<br>counter parts.|
|
|
196
|
+
|`confirmed`|`confirmed`|Ensures a field value as confirmed using a _confirmation convention. This is mainly used for<br>password confirmation field.<br>For example: If the password field name is password, then another field called password_confirmation<br>must exist and should have the same value as the actual field.|
|
|
197
|
+
|`creditCard`|`credit_card`|Ensures a field value must be a valid credit card number.|
|
|
198
|
+
|`cvv`|`cvv`|Ensures a field value must be a CVV number.|
|
|
199
|
+
|`date`|`date`|Ensures the field under validation is a valid date. The value can be a date object or a valid date<br>string.|
|
|
200
|
+
|`dateFormat`|`date_format:DD-MM-YYYY`|Ensures the date or date time is valid as the one of the defined formats.|
|
|
201
|
+
|`debitCard`|`debit_card`|Ensures a field value must be a valid debit card number.|
|
|
202
|
+
|`different`|`different:other_field`|Ensures the value of the field under validation is always different from the targeted field value.|
|
|
203
|
+
|`dimension`|`rv.dimension('width=200px,height=200px')`|Ensures the The file under validation must be an image meeting the dimension constraints as<br>specified by the accppeted params like: height=200,max_height=200,width=200,max_width=200,ratio=1.2. Passed as its own call, not inside the `rule` chain — see the reactive form example above.|
|
|
204
|
+
|`email`|`email`|Ensures the field under validation is a valid email format.|
|
|
205
|
+
|`endsWith`|`ends_with:a,b`|Ensure the value of field under validation ends with a certain substr. This validation will also<br>trim whitespaces before making the check|
|
|
206
|
+
|`equals`|`equals:a`|Ensures the value of the field under validation exactly matches the given value.|
|
|
207
|
+
|`exists`|`rv.exists({url:'...'})`|Ensures the value exists in the database. Only <b>GET</b> and <b>POST</b> methods are<br>allowed for remote validation; the default method is <b>GET</b>. Passed as its own call, not inside the `rule` chain.|
|
|
208
|
+
|`image`|`image`|Ensures the upload file is an valid image file|
|
|
209
|
+
|`in`|`in:a,b`|Ensures the value of a given field matches one of expected values.|
|
|
210
|
+
|`includes`|`includes:abcd,efgh`|Ensures the value of field under validation contains a given substring.|
|
|
211
|
+
|`integer`|`integer`|Ensures the value is a valid integer. Also string representation of a number will return true.|
|
|
212
|
+
|`ip`|`ip`|Ensures the value is a valid ip address as per ipv4 and ipv6 specs.|
|
|
213
|
+
|`ipv4`|`ipv4`|Ensures the value is a valid ip address as per ipv4 spec only.|
|
|
214
|
+
|`ipv6`|`ipv6`|Ensures the value is a valid ip address as per ipv6 spec only.|
|
|
215
|
+
|`json`|`json`|Ensures the value of field under validation is safe to be parsed using JSON.parse method.|
|
|
216
|
+
|`max`|`max:10`|Ensures the length of a string or array or number is not greater than the defined length.|
|
|
217
|
+
|`min`|`min:10`|Ensures the length of a string or array or number is not is not less than the expected length|
|
|
218
|
+
|`mimes`|`mimes:png,jpg`|Ensures the file must have a MIME type corresponding to one of the listed extensions.|
|
|
219
|
+
|`notEquals`|`not_equals:10`|Makes sure that the value of field under validation is not same as the defined value.|
|
|
220
|
+
|`notIn`|`not_in:a,b,c`|Makes sure that the value of field under validation is not from one of the defined values.|
|
|
221
|
+
|`notRegex`|`not_regex:(?=.*[0-9])`|Ensures the value of field under validation, passes the regex test. The regex can be defined as a<br>string or a RegExp object.|
|
|
222
|
+
|`number`|`number`|Makes sure that the value of field under validation is a valid number. The validation will pass for<br>floats too, since it uses typeof internally.|
|
|
223
|
+
|`phoneNo`|`phone_no`|Makes sure that the value of field under validation is a valid phone number. In default phone number<br>is validate more than 10 Style of number.To override the default behaviour pass new regex expression<br>to validate the number.|
|
|
224
|
+
|`range`|`range:5,10`|Ensures the value of field under validation is under a given range. The values will be cased to<br>Number automatically.|
|
|
225
|
+
|`regex`|`regex:(?=.*[0-9])`|Ensures the value of field under validation, passes the regex test. The regex can be defined as a<br>string or a RegExp object.|
|
|
226
|
+
|`required`|`required`|Ensures the value of field under validation is not empty.|
|
|
227
|
+
|`requiredIf`|`required_if:field,value`|Ensures the field under validation must be present and not empty if the anotherfield field is equal<br>to any value. The Match with field must be define or initialized or placed before validated field.|
|
|
228
|
+
|`requiredUnless`|`required_unless:field,value`|Ensures the field under validation must be present and not empty unless the anotherfield field is<br>equal to any value. The Match with fields must be define or initialized or placed before validated<br>field.|
|
|
229
|
+
|`requiredWith`|`required_with:field1,field2`|Ensure The field under validation must be present and not empty only if any of the other specified<br>fields are present. The Match with fields must be define or initialized or placed before validated<br>field.|
|
|
230
|
+
|`requiredWithAll`|`required_with_all:field1,field2`|Ensure The field under validation must be present and not empty only if all of the other specified<br>fields are present. The Match with fields must be define or initialized or placed before validated<br>field.|
|
|
231
|
+
|`requiredWithout`|`required_without:field1,field2`|Ensure The field under validation must be present and not empty only when any of the other specified<br>fields are not present. The Match with fields must be define or initialized or placed before<br>validated field.|
|
|
232
|
+
|`requiredWithoutAll`|`required_without_all:field1,field2`|Ensure The field under validation must be present and not empty only when all of the other specified<br>fields are not present. The Match with fields must be define or initialized or placed before<br>validated field.|
|
|
233
|
+
|`same`|`same:other_field`|Ensures the value of 2 fields are same.|
|
|
234
|
+
|`size`|`size:120`|Ensures the size of the file not more than the specific size (in KB).|
|
|
235
|
+
|`startsWith`|`starts_with:a,b`|Ensures the value of 2 fields are same.|
|
|
236
|
+
|`string`|`string`|Ensures the value is a string.|
|
|
237
|
+
|`strength`|`strength`| Make sure the value strength should mach pre defined regex expression.<br><br> Add or overide with new regex expression from root config.<br> Add or modify progess bar color combination from root config.<br> <ul> <b>a</b> : String must be 8 charecter long.<br> <b>b</b> : String must contain one uppercase letter.<br> <b>c</b> : String must contain one spatial charecter.<br> <b>d</b> : String must contain one digit.<br> <b>b</b> : String must contain one lowecase letter.<br> </ul> |
|
|
238
|
+
|`under`|`under:10`|Ensures the value of a field is under a certain value. All values will be casted to Number|
|
|
239
|
+
|`url`|`url`|Ensures the value is a valid URL format.|
|
|
240
|
+
|`uuid`|`uuid`|Ensures the value is a valid UUID format.|
|
|
241
|
+
|`unique`|`rv.unique({url:'...'})`|Ensures the value is unique in the database. Only <b>GET</b> and <b>POST</b> methods are<br>allowed for remote validation; the default method is <b>GET</b>. Passed as its own call, not inside the `rule` chain.|
|
|
242
|
+
|`video`|`video`|Ensures the upload file is an valid video file|
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
This project is licensed under the terms of the MIT license.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormGroupDirective, NgForm } from '@angular/forms';
|
|
2
2
|
import { Directive, Inject, Input, Optional } from '@angular/core';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
|
-
export class
|
|
4
|
+
export class ErrorTriggerOn {
|
|
5
5
|
constructor(FormGroupDirective, NgForm) {
|
|
6
6
|
this.FormGroupDirective = FormGroupDirective;
|
|
7
7
|
this.NgForm = NgForm;
|
|
@@ -11,9 +11,9 @@ export class ErrorTriggerOnDirective {
|
|
|
11
11
|
this.FormGroupDirective && (this.FormGroupDirective.errorTriggerOn = triggerState);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type:
|
|
14
|
+
ErrorTriggerOn.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ErrorTriggerOn, deps: [{ token: FormGroupDirective, optional: true }, { token: NgForm, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
|
|
15
|
+
ErrorTriggerOn.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.3.0", type: ErrorTriggerOn, selector: "form[ErrorTriggerOn]", inputs: { message: ["ErrorTriggerOn", "message"] }, ngImport: i0 });
|
|
16
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ErrorTriggerOn, decorators: [{
|
|
17
17
|
type: Directive,
|
|
18
18
|
args: [{
|
|
19
19
|
selector: 'form[ErrorTriggerOn]'
|
|
@@ -32,4 +32,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
|
|
|
32
32
|
type: Input,
|
|
33
33
|
args: ['ErrorTriggerOn']
|
|
34
34
|
}] } });
|
|
35
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3ItdHJpZ2dlci1vbi5kaXJlY3RpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9wcm9qZWN0cy9uZy1hYnNvbHV0ZS12YWxpZGF0b3Ivc3JjL2xpYi9kaXJlY3RpdmUvZXJyb3ItdHJpZ2dlci9lcnJvci10cmlnZ2VyLW9uLmRpcmVjdGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDNUQsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLFFBQVEsRUFBRSxNQUFNLGVBQWUsQ0FBQzs7QUFNbkUsTUFBTSxPQUFPLGNBQWM7SUFFdkIsWUFDb0Qsa0JBQXVDLEVBQ25ELE1BQWU7UUFESCx1QkFBa0IsR0FBbEIsa0JBQWtCLENBQXFCO1FBQ25ELFdBQU0sR0FBTixNQUFNLENBQVM7SUFDbkQsQ0FBQztJQUVMLElBQ0ksT0FBTyxDQUFDLFlBQWlDO1FBQ3pDLElBQUksQ0FBQyxNQUFNLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLGNBQWMsR0FBRyxZQUFZLENBQUMsQ0FBQTtRQUMxRCxJQUFJLENBQUMsa0JBQWtCLElBQUksQ0FBQyxJQUFJLENBQUMsa0JBQWtCLENBQUMsY0FBYyxHQUFHLFlBQVksQ0FBQyxDQUFBO0lBQ3RGLENBQUM7OzJHQVhRLGNBQWMsa0JBR0Msa0JBQWtCLDZCQUNsQixNQUFNOytGQUpyQixjQUFjOzJGQUFkLGNBQWM7a0JBSDFCLFNBQVM7bUJBQUM7b0JBQ1AsUUFBUSxFQUFFLHNCQUFzQjtpQkFDbkM7OzBCQUlRLFFBQVE7OzBCQUFJLE1BQU07MkJBQUMsa0JBQWtCOzswQkFDckMsUUFBUTs7MEJBQUksTUFBTTsyQkFBQyxNQUFNOzRDQUkxQixPQUFPO3NCQURWLEtBQUs7dUJBQUMsZ0JBQWdCIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgRm9ybUdyb3VwRGlyZWN0aXZlLCBOZ0Zvcm0gfSBmcm9tICdAYW5ndWxhci9mb3Jtcyc7XG5pbXBvcnQgeyBEaXJlY3RpdmUsIEluamVjdCwgSW5wdXQsIE9wdGlvbmFsIH0gZnJvbSAnQGFuZ3VsYXIvY29yZSc7XG5pbXBvcnQgeyBFcnJvclRyaWdnZXJTdGF0ZSwgRm9ybUdyb3VwRGlyZWN0aXZlMiwgTmdGb3JtMiB9IGZyb20gJy4uLy4uL2ludGVyZmFjZSc7XG5cbkBEaXJlY3RpdmUoe1xuICAgIHNlbGVjdG9yOiAnZm9ybVtFcnJvclRyaWdnZXJPbl0nXG59KVxuZXhwb3J0IGNsYXNzIEVycm9yVHJpZ2dlck9uIHtcblxuICAgIGNvbnN0cnVjdG9yKFxuICAgICAgICBAT3B0aW9uYWwoKSBASW5qZWN0KEZvcm1Hcm91cERpcmVjdGl2ZSkgcHJpdmF0ZSBGb3JtR3JvdXBEaXJlY3RpdmU6IEZvcm1Hcm91cERpcmVjdGl2ZTIsXG4gICAgICAgIEBPcHRpb25hbCgpIEBJbmplY3QoTmdGb3JtKSBwcml2YXRlIE5nRm9ybTogTmdGb3JtMlxuICAgICkgeyB9XG5cbiAgICBASW5wdXQoJ0Vycm9yVHJpZ2dlck9uJylcbiAgICBzZXQgbWVzc2FnZSh0cmlnZ2VyU3RhdGU6IEVycm9yVHJpZ2dlclN0YXRlW10pIHtcbiAgICAgICAgdGhpcy5OZ0Zvcm0gJiYgKHRoaXMuTmdGb3JtLmVycm9yVHJpZ2dlck9uID0gdHJpZ2dlclN0YXRlKVxuICAgICAgICB0aGlzLkZvcm1Hcm91cERpcmVjdGl2ZSAmJiAodGhpcy5Gb3JtR3JvdXBEaXJlY3RpdmUuZXJyb3JUcmlnZ2VyT24gPSB0cmlnZ2VyU3RhdGUpXG4gICAgfVxufVxuIl19
|