@lagoshny/ngx-validation-messages 21.0.3 → 21.1.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 21.1.0 (2026-04-21)
|
|
2
|
+
#### Separated material and standalone components
|
|
3
|
+
Separated material and standalone components to allow use lib without material.
|
|
4
|
+
Added docs how to use lib with i18n validation messages.
|
|
5
|
+
|
|
6
|
+
Break changes:
|
|
7
|
+
- Extracted directive `ngxValidationMessages` to use with material ui `mat-error` component. Now you need to import additionally `NgxMatValidationMessagesDirective` to use `ngxValidationMessages`.
|
|
8
|
+
|
|
1
9
|
## 21.0.3 (2025-12-21)
|
|
2
10
|
#### Updated lib to standalone
|
|
3
11
|
Added test configuration.
|
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ This library allows you to decrease boilerplate code when handling validations e
|
|
|
50
50
|
2. [Form driven approach (reactive)](#2-form-driven-approach-reactive)
|
|
51
51
|
3. [Without component as error container](#3-use-without-component-as-error-container)
|
|
52
52
|
4. [With material ui components using mat-error component](#4-with-material-ui-components-using-mat-error-component)
|
|
53
|
+
5. [I18n with Transloco](#5-i18n-with-transloco)
|
|
53
54
|
3. [How it works?](#How-it-works?)
|
|
54
55
|
4. [Advanced configuration](#Advanced-configuration)
|
|
55
56
|
1. [Override configured validation messages](#Override-configured-validation-messages)
|
|
@@ -277,7 +278,13 @@ If you need simple to display error message in common style as it does `ngx-vali
|
|
|
277
278
|
````
|
|
278
279
|
|
|
279
280
|
#### 4. With material ui components using mat-error component
|
|
280
|
-
|
|
281
|
+
Import directive:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { NgxMatValidationMessagesDirective } from '@lagoshny/ngx-validation-messages';
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
And use it with `mat-error`:
|
|
281
288
|
|
|
282
289
|
````html
|
|
283
290
|
<form [formGroup]="taskForm">
|
|
@@ -293,21 +300,71 @@ It's simple to use `ngx-validation-messages` with material ui `mat-error` compon
|
|
|
293
300
|
|
|
294
301
|
After that if `FormControl` with name `email` will be invalid, then configured error messages for validators applied to `email` will be shown in material ui style.
|
|
295
302
|
|
|
296
|
-
|
|
303
|
+
#### 5. I18n with Transloco
|
|
304
|
+
You can use i18n with Transloco to provide localized messages for validation errors.
|
|
305
|
+
|
|
306
|
+
Define `ValidationI18nService` to provide localized messages and update the lib configuration after change the language:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
export const validationMessageKeys: Readonly<Record<string, string>> = {
|
|
310
|
+
required: 'validation.required',
|
|
311
|
+
email: 'validation.email'
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
@Injectable({ providedIn: 'root' })
|
|
315
|
+
export class ValidationI18nService {
|
|
316
|
+
private readonly transloco = inject(TranslocoService);
|
|
317
|
+
private readonly destroyRef = inject(DestroyRef);
|
|
318
|
+
private readonly ngxConfig = inject<NgxValidationMessagesConfig>(NGX_VALIDATION_MESSAGES_CONFIG);
|
|
319
|
+
|
|
320
|
+
constructor() {
|
|
321
|
+
this.transloco.langChanges$
|
|
322
|
+
.pipe(
|
|
323
|
+
startWith(this.transloco.getActiveLang()),
|
|
324
|
+
distinctUntilChanged(),
|
|
325
|
+
switchMap((lang) => this.transloco.load(lang).pipe(map(() => lang))),
|
|
326
|
+
takeUntilDestroyed(this.destroyRef),
|
|
327
|
+
)
|
|
328
|
+
.subscribe((lang) => this.apply(lang));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private apply(lang: string): void {
|
|
332
|
+
for (const [validator, key] of Object.entries(validationMessageKeys)) {
|
|
333
|
+
this.ngxConfig.messages[validator] = this.transloco.translate(key, {}, lang);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
297
338
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
339
|
+
And update application configuration:
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
export const validationConfig: NgxValidationMessagesConfig = {
|
|
343
|
+
messages: {},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
export const appConfig: ApplicationConfig = {
|
|
347
|
+
providers: [
|
|
348
|
+
provideTransloco({
|
|
349
|
+
config: {
|
|
350
|
+
availableLangs: ['en', 'de'],
|
|
351
|
+
defaultLang: 'en',
|
|
352
|
+
},
|
|
353
|
+
loader: TranslocoHttpLoader,
|
|
354
|
+
}),
|
|
355
|
+
provideNgxValidationMessages(validationConfig),
|
|
356
|
+
provideEnvironmentInitializer(() => {
|
|
357
|
+
inject(ValidationI18nService);
|
|
358
|
+
}),
|
|
359
|
+
],
|
|
360
|
+
};
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
See more about i18n with Transloco in [ngx-transloco](https://github.com/ngneat/transloco).
|
|
307
364
|
|
|
308
365
|
## How it works?
|
|
309
366
|
|
|
310
|
-
In both cases `NgxValidationMessagesComponent` will get validation messages for each applied to form control validator from passed configuration object to `provideNgxValidationMessages`
|
|
367
|
+
In both cases `NgxValidationMessagesComponent` and `NgxMatValidationMessagesDirective` will get validation messages for each applied to form control validator from passed configuration object to `provideNgxValidationMessages`
|
|
311
368
|
|
|
312
369
|
For example, if you pass configuration like this:
|
|
313
370
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, ViewChild, Input, Component,
|
|
3
|
-
import * as
|
|
2
|
+
import { InjectionToken, ViewChild, Input, Component, inject, Injectable, Directive, ContentChildren, ElementRef, Renderer2 } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/common';
|
|
4
4
|
import { CommonModule } from '@angular/common';
|
|
5
|
-
import * as i3 from '@angular/material/form-field';
|
|
6
|
-
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
7
5
|
|
|
8
6
|
const NGX_VALIDATION_MESSAGES_CONFIG = new InjectionToken('NgxValidationMessagesConfig');
|
|
9
7
|
const DEFAULT_CONFIG = {
|
|
@@ -25,13 +23,13 @@ class NgxCustomMessageComponent {
|
|
|
25
23
|
* Contains overridden message for validator.
|
|
26
24
|
*/
|
|
27
25
|
message;
|
|
28
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.
|
|
29
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.
|
|
26
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxCustomMessageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
27
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.9", type: NgxCustomMessageComponent, isStandalone: true, selector: "ngx-custom-message", inputs: { validatorName: ["forValidator", "validatorName"] }, viewQueries: [{ propertyName: "message", first: true, predicate: ["message"], descendants: true }], ngImport: i0, template: `
|
|
30
28
|
<div #message>
|
|
31
29
|
<ng-content></ng-content>
|
|
32
30
|
</div>`, isInline: true });
|
|
33
31
|
}
|
|
34
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.
|
|
32
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxCustomMessageComponent, decorators: [{
|
|
35
33
|
type: Component,
|
|
36
34
|
args: [{
|
|
37
35
|
standalone: true,
|
|
@@ -50,57 +48,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.2", ngImpor
|
|
|
50
48
|
args: ['message']
|
|
51
49
|
}] } });
|
|
52
50
|
|
|
53
|
-
/**
|
|
54
|
-
* Allows to specify custom validator message to override default message.
|
|
55
|
-
*
|
|
56
|
-
* It's alternative for {@link NgxCustomMessageComponent}.
|
|
57
|
-
* If you want to use standard html tags to define custom message, use this directive on html tag within
|
|
58
|
-
* {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,
|
|
59
|
-
* otherwise use {@link NgxCustomMessageComponent}.
|
|
60
|
-
*/
|
|
61
|
-
class NgxValidatorNameDirective {
|
|
62
|
-
elem;
|
|
63
|
-
/**
|
|
64
|
-
* The name of the validator for which you want to override the message.
|
|
65
|
-
*/
|
|
66
|
-
validatorName;
|
|
67
|
-
/**
|
|
68
|
-
* Contains overridden message for validator.
|
|
69
|
-
*/
|
|
70
|
-
message;
|
|
71
|
-
constructor(elem) {
|
|
72
|
-
this.elem = elem;
|
|
73
|
-
}
|
|
74
|
-
ngAfterViewInit() {
|
|
75
|
-
this.message = this.elem.nativeElement.innerText;
|
|
76
|
-
}
|
|
77
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.2", ngImport: i0, type: NgxValidatorNameDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
78
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.2", type: NgxValidatorNameDirective, isStandalone: true, selector: "[ngxValidatorName]", inputs: { validatorName: "validatorName" }, ngImport: i0 });
|
|
79
|
-
}
|
|
80
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.2", ngImport: i0, type: NgxValidatorNameDirective, decorators: [{
|
|
81
|
-
type: Directive,
|
|
82
|
-
args: [{
|
|
83
|
-
standalone: true,
|
|
84
|
-
selector: '[ngxValidatorName]'
|
|
85
|
-
}]
|
|
86
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { validatorName: [{
|
|
87
|
-
type: Input
|
|
88
|
-
}] } });
|
|
89
|
-
|
|
90
51
|
/**
|
|
91
52
|
* Service allows getting validation messages from client's settings.
|
|
92
53
|
* Injecting {@link NgxValidationMessagesConfig} to get client's configuration with validation messages.
|
|
93
54
|
*/
|
|
94
55
|
class NgxValidationMessagesService {
|
|
95
|
-
messagesConfig;
|
|
96
56
|
static SERVER_ERRORS = 'serverErrors';
|
|
97
57
|
/**
|
|
98
58
|
* Regular expression to find params placeholder '#[paramName]'.
|
|
99
59
|
*/
|
|
100
60
|
paramsRegExp = new RegExp(/#[[a-zA-Z_\\-]*]/);
|
|
101
|
-
|
|
102
|
-
this.messagesConfig = messagesConfig;
|
|
103
|
-
}
|
|
61
|
+
messagesConfig = inject(NGX_VALIDATION_MESSAGES_CONFIG);
|
|
104
62
|
/**
|
|
105
63
|
* Get validation message for specified validator.
|
|
106
64
|
*
|
|
@@ -149,31 +107,58 @@ class NgxValidationMessagesService {
|
|
|
149
107
|
return '';
|
|
150
108
|
}, obj) ?? '';
|
|
151
109
|
}
|
|
152
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.
|
|
153
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.
|
|
110
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
111
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesService, providedIn: 'root' });
|
|
154
112
|
}
|
|
155
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.
|
|
113
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesService, decorators: [{
|
|
156
114
|
type: Injectable,
|
|
157
115
|
args: [{
|
|
158
116
|
providedIn: 'root',
|
|
159
117
|
}]
|
|
160
|
-
}]
|
|
161
|
-
type: Inject,
|
|
162
|
-
args: [NGX_VALIDATION_MESSAGES_CONFIG]
|
|
163
|
-
}] }] });
|
|
118
|
+
}] });
|
|
164
119
|
|
|
165
120
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
121
|
+
* Allows to specify custom validator message to override default message.
|
|
122
|
+
*
|
|
123
|
+
* It's alternative for {@link NgxCustomMessageComponent}.
|
|
124
|
+
* If you want to use standard html tags to define custom message, use this directive on html tag within
|
|
125
|
+
* {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,
|
|
126
|
+
* otherwise use {@link NgxCustomMessageComponent}.
|
|
168
127
|
*/
|
|
169
|
-
class
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
128
|
+
class NgxValidatorNameDirective {
|
|
129
|
+
elem;
|
|
130
|
+
/**
|
|
131
|
+
* The name of the validator for which you want to override the message.
|
|
132
|
+
*/
|
|
133
|
+
validatorName;
|
|
134
|
+
/**
|
|
135
|
+
* Contains overridden message for validator.
|
|
136
|
+
*/
|
|
137
|
+
message;
|
|
138
|
+
constructor(elem) {
|
|
139
|
+
this.elem = elem;
|
|
140
|
+
}
|
|
141
|
+
ngAfterViewInit() {
|
|
142
|
+
this.message = this.elem.nativeElement.innerText;
|
|
143
|
+
}
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidatorNameDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
145
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: NgxValidatorNameDirective, isStandalone: true, selector: "[ngxValidatorName]", inputs: { validatorName: "validatorName" }, ngImport: i0 });
|
|
146
|
+
}
|
|
147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidatorNameDirective, decorators: [{
|
|
148
|
+
type: Directive,
|
|
149
|
+
args: [{
|
|
150
|
+
standalone: true,
|
|
151
|
+
selector: '[ngxValidatorName]'
|
|
152
|
+
}]
|
|
153
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { validatorName: [{
|
|
154
|
+
type: Input
|
|
155
|
+
}] } });
|
|
156
|
+
|
|
157
|
+
class NgxValidationMessagesBase {
|
|
173
158
|
/**
|
|
174
159
|
* Form control for which need to show validation messages.
|
|
175
160
|
*/
|
|
176
|
-
formControl;
|
|
161
|
+
formControl = null;
|
|
177
162
|
/**
|
|
178
163
|
* Contains {@link NgxCustomMessageComponent} if present.
|
|
179
164
|
*/
|
|
@@ -182,30 +167,18 @@ class NgxValidationMessagesComponent {
|
|
|
182
167
|
* Contains {@link NgxValidatorNameDirective} if present.
|
|
183
168
|
*/
|
|
184
169
|
customMsgDirective;
|
|
185
|
-
isMaterialError = false;
|
|
186
170
|
/**
|
|
187
171
|
* Key to get default validation message.
|
|
188
172
|
*/
|
|
189
173
|
defaultError = 'error';
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.ngxValidationConfig = ngxValidationConfig;
|
|
193
|
-
this.ngxValidationMessagesService = ngxValidationMessagesService;
|
|
194
|
-
this.directiveElementRef = directiveElementRef;
|
|
195
|
-
}
|
|
196
|
-
ngAfterViewInit() {
|
|
197
|
-
if (this.directiveElementRef && this.directiveElementRef.nativeElement
|
|
198
|
-
&& this.directiveElementRef.nativeElement.nodeName) {
|
|
199
|
-
this.isMaterialError = this.materialErrorElement.toLocaleUpperCase()
|
|
200
|
-
=== this.directiveElementRef.nativeElement.nodeName.toLocaleUpperCase();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
174
|
+
ngxValidationConfig = inject(NGX_VALIDATION_MESSAGES_CONFIG);
|
|
175
|
+
ngxValidationMessagesService = inject(NgxValidationMessagesService);
|
|
203
176
|
/**
|
|
204
177
|
* Get all validation messages for specified form control.
|
|
205
178
|
*/
|
|
206
179
|
get errorMessages() {
|
|
207
180
|
const result = [];
|
|
208
|
-
if (!this.formControl || !this.formControl.
|
|
181
|
+
if (!this.formControl?.errors || !(this.formControl.touched || this.formControl.dirty)) {
|
|
209
182
|
return result;
|
|
210
183
|
}
|
|
211
184
|
if (this.customMsgComponent && this.customMsgComponent.length > 0) {
|
|
@@ -234,7 +207,7 @@ class NgxValidationMessagesComponent {
|
|
|
234
207
|
}
|
|
235
208
|
processingCustomMessages(customMessage) {
|
|
236
209
|
customMessage.forEach((msg) => {
|
|
237
|
-
if (!this.formControl.errors[msg.validatorName]) {
|
|
210
|
+
if (this.formControl == null || !this.formControl?.errors || !this.formControl.errors[msg.validatorName]) {
|
|
238
211
|
return;
|
|
239
212
|
}
|
|
240
213
|
let message = (msg instanceof NgxCustomMessageComponent)
|
|
@@ -245,19 +218,12 @@ class NgxValidationMessagesComponent {
|
|
|
245
218
|
: this.formControl.errors[msg.validatorName] = { customMessage: message };
|
|
246
219
|
});
|
|
247
220
|
}
|
|
248
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.
|
|
249
|
-
static
|
|
221
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
222
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: NgxValidationMessagesBase, isStandalone: true, inputs: { formControl: ["for", "formControl"] }, queries: [{ propertyName: "customMsgComponent", predicate: NgxCustomMessageComponent }, { propertyName: "customMsgDirective", predicate: NgxValidatorNameDirective }], ngImport: i0 });
|
|
250
223
|
}
|
|
251
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.
|
|
252
|
-
type:
|
|
253
|
-
|
|
254
|
-
CommonModule,
|
|
255
|
-
MatFormFieldModule,
|
|
256
|
-
], template: "<!--To show error messages standalone without component-->\n@if (!formControl && customMsgComponent.length == 0 && customMsgDirective.length == 0) {\n <div\n [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n <ng-content></ng-content>\n </span>\n </div>\n}\n\n@if (errorMessages.length > 0) {\n <!--To show error messages in material ui style-->\n @if (isMaterialError) {\n @for (message of errorMessages; track message) {\n <mat-error>{{ message }}</mat-error>\n }\n } @else {\n <div [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n @for (message of errorMessages; track message) {\n <div>\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n {{ message }}\n </span>\n </div>\n }\n </div>\n }\n <!--To show error messages in user style-->\n}\n", styles: [".ngx_vm__def_error_block{position:relative;display:inline-block;width:100%;margin-bottom:10px;margin-top:2px;padding:8px;border-radius:0;background:#c51244;box-shadow:1px 1px 1px #aaa;opacity:.8}.ngx_vm__def_error_text{color:#fff}\n"] }]
|
|
257
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
258
|
-
type: Inject,
|
|
259
|
-
args: [NGX_VALIDATION_MESSAGES_CONFIG]
|
|
260
|
-
}] }, { type: NgxValidationMessagesService }, { type: i0.ElementRef }], propDecorators: { formControl: [{
|
|
224
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesBase, decorators: [{
|
|
225
|
+
type: Directive
|
|
226
|
+
}], propDecorators: { formControl: [{
|
|
261
227
|
type: Input,
|
|
262
228
|
args: ['for']
|
|
263
229
|
}], customMsgComponent: [{
|
|
@@ -268,6 +234,113 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.2", ngImpor
|
|
|
268
234
|
args: [NgxValidatorNameDirective]
|
|
269
235
|
}] } });
|
|
270
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Attribute directive for Material form fields.
|
|
239
|
+
* Usage: <mat-error ngxValidationMessages [for]="form.get('email')"></mat-error>
|
|
240
|
+
*/
|
|
241
|
+
class NgxMatValidationMessagesDirective extends NgxValidationMessagesBase {
|
|
242
|
+
hostElementRef = inject((ElementRef));
|
|
243
|
+
renderer = inject(Renderer2);
|
|
244
|
+
renderedMessages = [];
|
|
245
|
+
dynamicMessageElements = [];
|
|
246
|
+
ngDoCheck() {
|
|
247
|
+
if (!this.formControl) {
|
|
248
|
+
this.resetRenderedMessages();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const currentMessages = this.errorMessages;
|
|
252
|
+
if (this.isEqualMessageSet(this.renderedMessages, currentMessages)) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.renderedMessages = [...currentMessages];
|
|
256
|
+
this.renderMessages(currentMessages);
|
|
257
|
+
}
|
|
258
|
+
ngOnDestroy() {
|
|
259
|
+
this.resetRenderedMessages();
|
|
260
|
+
}
|
|
261
|
+
renderMessages(messages) {
|
|
262
|
+
const hostElement = this.hostElementRef.nativeElement;
|
|
263
|
+
this.renderer.setProperty(hostElement, 'textContent', messages[0] ?? '');
|
|
264
|
+
this.syncAdditionalMessageElements(messages.slice(1));
|
|
265
|
+
}
|
|
266
|
+
syncAdditionalMessageElements(messages) {
|
|
267
|
+
while (this.dynamicMessageElements.length < messages.length) {
|
|
268
|
+
this.dynamicMessageElements.push(this.createDynamicMatErrorElement());
|
|
269
|
+
}
|
|
270
|
+
while (this.dynamicMessageElements.length > messages.length) {
|
|
271
|
+
const errorElement = this.dynamicMessageElements.pop();
|
|
272
|
+
if (errorElement?.parentNode) {
|
|
273
|
+
this.renderer.removeChild(errorElement.parentNode, errorElement);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const hostElement = this.hostElementRef.nativeElement;
|
|
277
|
+
const parentElement = hostElement.parentNode;
|
|
278
|
+
let previousNode = hostElement;
|
|
279
|
+
this.dynamicMessageElements.forEach((errorElement, index) => {
|
|
280
|
+
this.renderer.setProperty(errorElement, 'textContent', messages[index]);
|
|
281
|
+
if (!parentElement) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.renderer.insertBefore(parentElement, errorElement, previousNode.nextSibling);
|
|
285
|
+
previousNode = errorElement;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
createDynamicMatErrorElement() {
|
|
289
|
+
const errorElement = this.renderer.createElement('mat-error');
|
|
290
|
+
const hostClasses = this.hostElementRef.nativeElement.className;
|
|
291
|
+
if (hostClasses) {
|
|
292
|
+
this.renderer.setAttribute(errorElement, 'class', hostClasses);
|
|
293
|
+
}
|
|
294
|
+
return errorElement;
|
|
295
|
+
}
|
|
296
|
+
destroyDynamicMessageElements() {
|
|
297
|
+
this.dynamicMessageElements.forEach((errorElement) => {
|
|
298
|
+
if (errorElement.parentNode) {
|
|
299
|
+
this.renderer.removeChild(errorElement.parentNode, errorElement);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
this.dynamicMessageElements = [];
|
|
303
|
+
}
|
|
304
|
+
resetRenderedMessages() {
|
|
305
|
+
if (this.renderedMessages.length === 0 && this.dynamicMessageElements.length === 0) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this.renderedMessages = [];
|
|
309
|
+
this.renderer.setProperty(this.hostElementRef.nativeElement, 'textContent', '');
|
|
310
|
+
this.destroyDynamicMessageElements();
|
|
311
|
+
}
|
|
312
|
+
isEqualMessageSet(previous, current) {
|
|
313
|
+
if (previous.length !== current.length) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
return previous.every((message, index) => message === current[index]);
|
|
317
|
+
}
|
|
318
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxMatValidationMessagesDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
319
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: NgxMatValidationMessagesDirective, isStandalone: true, selector: "mat-error[ngxValidationMessages]", usesInheritance: true, ngImport: i0 });
|
|
320
|
+
}
|
|
321
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxMatValidationMessagesDirective, decorators: [{
|
|
322
|
+
type: Directive,
|
|
323
|
+
args: [{
|
|
324
|
+
standalone: true,
|
|
325
|
+
selector: 'mat-error[ngxValidationMessages]'
|
|
326
|
+
}]
|
|
327
|
+
}] });
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Component for displaying validation messages, supports child components of type {@link NgxCustomMessageComponent}
|
|
331
|
+
* and html elements with directive {@link NgxValidatorNameDirective} to override validation messages.
|
|
332
|
+
*/
|
|
333
|
+
class NgxValidationMessagesComponent extends NgxValidationMessagesBase {
|
|
334
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
335
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.9", type: NgxValidationMessagesComponent, isStandalone: true, selector: "ngx-validation-messages", usesInheritance: true, ngImport: i0, template: "<!--To show error messages standalone without component-->\n@if (!formControl && customMsgComponent.length == 0 && customMsgDirective.length == 0) {\n <div\n [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n <ng-content></ng-content>\n </span>\n </div>\n}\n\n@if (errorMessages.length > 0) {\n <div [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n @for (message of errorMessages; track message) {\n <div>\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n {{ message }}\n </span>\n </div>\n }\n </div>\n}\n", styles: [".ngx_vm__def_error_block{position:relative;display:inline-block;width:100%;margin-bottom:10px;margin-top:2px;padding:8px;border-radius:0;background:#c51244;box-shadow:1px 1px 1px #aaa;opacity:.8}.ngx_vm__def_error_text{color:#fff}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
|
|
336
|
+
}
|
|
337
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxValidationMessagesComponent, decorators: [{
|
|
338
|
+
type: Component,
|
|
339
|
+
args: [{ standalone: true, selector: 'ngx-validation-messages', imports: [
|
|
340
|
+
CommonModule,
|
|
341
|
+
], template: "<!--To show error messages standalone without component-->\n@if (!formControl && customMsgComponent.length == 0 && customMsgDirective.length == 0) {\n <div\n [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n <ng-content></ng-content>\n </span>\n </div>\n}\n\n@if (errorMessages.length > 0) {\n <div [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n @for (message of errorMessages; track message) {\n <div>\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n {{ message }}\n </span>\n </div>\n }\n </div>\n}\n", styles: [".ngx_vm__def_error_block{position:relative;display:inline-block;width:100%;margin-bottom:10px;margin-top:2px;padding:8px;border-radius:0;background:#c51244;box-shadow:1px 1px 1px #aaa;opacity:.8}.ngx_vm__def_error_text{color:#fff}\n"] }]
|
|
342
|
+
}] });
|
|
343
|
+
|
|
271
344
|
function provideNgxValidationMessages(config) {
|
|
272
345
|
return [
|
|
273
346
|
{
|
|
@@ -293,5 +366,5 @@ function provideNgxValidationMessagesTesting(config) {
|
|
|
293
366
|
* Generated bundle index. Do not edit.
|
|
294
367
|
*/
|
|
295
368
|
|
|
296
|
-
export { NGX_VALIDATION_MESSAGES_CONFIG, NgxCustomMessageComponent, NgxValidationMessagesComponent, NgxValidatorNameDirective, provideNgxValidationMessages, provideNgxValidationMessagesTesting };
|
|
369
|
+
export { NGX_VALIDATION_MESSAGES_CONFIG, NgxCustomMessageComponent, NgxMatValidationMessagesDirective, NgxValidationMessagesComponent, NgxValidatorNameDirective, provideNgxValidationMessages, provideNgxValidationMessagesTesting };
|
|
297
370
|
//# sourceMappingURL=lagoshny-ngx-validation-messages.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lagoshny-ngx-validation-messages.mjs","sources":["../../../projects/ngx-validation-messages/src/lib/interface/ngx-validation-messages.config.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-custom-message/ngx-custom-message.component.ts","../../../projects/ngx-validation-messages/src/lib/directivies/ngx-validator-name.directive.ts","../../../projects/ngx-validation-messages/src/lib/service/ngx-validation-messages.service.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-validation-messages/ngx-validation-messages.component.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-validation-messages/ngx-validation-messages.component.html","../../../projects/ngx-validation-messages/src/lib/ngx-validation-messages.providers.ts","../../../projects/ngx-validation-messages/src/public-api.ts","../../../projects/ngx-validation-messages/src/lagoshny-ngx-validation-messages.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport const NGX_VALIDATION_MESSAGES_CONFIG: InjectionToken<NgxValidationMessagesConfig>\n = new InjectionToken<NgxValidationMessagesConfig>('NgxValidationMessagesConfig');\n\nexport interface NgxValidationMessagesConfig {\n\n /**\n * Object contains validation messages in validatorName: validatorMessage format.\n */\n messages: {\n [validatorName: string]: string;\n };\n\n /**\n * Define custom styles to display validation messages.\n */\n validationMessagesStyle?: {\n blockClassNames?: string;\n textClassNames?: string;\n };\n\n}\n\nexport const DEFAULT_CONFIG: NgxValidationMessagesConfig = {\n messages: {}\n}\n","import { Component, ElementRef, Input, ViewChild } from '@angular/core';\n\n\n/**\n * Component allows specifying custom validation message for the specified\n * validator to override default message.\n *\n * Use this component as child in {@link NgxValidationMessagesComponent}.\n */\n@Component({\n standalone: true,\n selector: 'ngx-custom-message',\n template: `\n <div #message>\n <ng-content></ng-content>\n </div>`,\n imports: []\n})\nexport class NgxCustomMessageComponent {\n\n /**\n * The name of the validator for which you want to override the message.\n */\n @Input('forValidator')\n public validatorName: string | undefined;\n\n /**\n * Contains overridden message for validator.\n */\n @ViewChild('message')\n public message: ElementRef | undefined;\n\n}\n","import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';\n\n/**\n * Allows to specify custom validator message to override default message.\n *\n * It's alternative for {@link NgxCustomMessageComponent}.\n * If you want to use standard html tags to define custom message, use this directive on html tag within\n * {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,\n * otherwise use {@link NgxCustomMessageComponent}.\n */\n@Directive({\n standalone: true,\n selector: '[ngxValidatorName]'\n})\nexport class NgxValidatorNameDirective implements AfterViewInit {\n\n /**\n * The name of the validator for which you want to override the message.\n */\n @Input()\n public validatorName: string | undefined;\n\n /**\n * Contains overridden message for validator.\n */\n public message: string | undefined;\n\n constructor(private elem: ElementRef) {\n }\n\n public ngAfterViewInit(): void {\n this.message = this.elem.nativeElement.innerText;\n }\n\n}\n","import { Inject, Injectable } from '@angular/core';\nimport {\n NGX_VALIDATION_MESSAGES_CONFIG,\n NgxValidationMessagesConfig\n} from '../interface/ngx-validation-messages.config';\n\n/**\n * Service allows getting validation messages from client's settings.\n * Injecting {@link NgxValidationMessagesConfig} to get client's configuration with validation messages.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class NgxValidationMessagesService {\n\n public static SERVER_ERRORS = 'serverErrors';\n\n /**\n * Regular expression to find params placeholder '#[paramName]'.\n */\n private paramsRegExp = new RegExp(/#[[a-zA-Z_\\\\-]*]/);\n\n constructor(@Inject(NGX_VALIDATION_MESSAGES_CONFIG) private messagesConfig: NgxValidationMessagesConfig) {\n }\n\n /**\n * Get validation message for specified validator.\n *\n * @param validatorName for which to get message\n * @param params passed from validator for more detailed validation message\n *\n * @returns string validation message\n */\n public getValidatorErrorMessages(validatorName: string, params?: object): string {\n const validationMessages = this.messagesConfig.messages;\n const validationMessage: string = validationMessages[validatorName];\n\n if (!validationMessage) {\n throw new Error('Validation message for validator: ' + validatorName\n + ' cannot be found, please check validation message key for validator it is case sensitive.');\n }\n\n if (params) {\n return this.expandParameterizedTemplateMessage(validationMessage, params);\n }\n\n return validationMessage;\n }\n\n public expandParameterizedTemplateMessage(msg: string, params: object): string {\n while (this.paramsRegExp.test(msg)) {\n const foundParams = this.paramsRegExp.exec(msg);\n foundParams?.forEach(value => {\n const paramPlaceholder = value;\n value = value.replace('#[', '').replace(']', '');\n msg = msg.replace(paramPlaceholder, this.getParameter(params, value));\n });\n }\n\n return msg;\n }\n\n /**\n * A utilitarian method to get a property from an object.\n * if there is no property, an empty string is returned.\n *\n * @param obj from which the property must be obtained\n * @param prop property name\n *\n * @return property value or empty string\n */\n private getParameter(obj: unknown, prop: string): string {\n return prop.split('.').reduce((acc: unknown, key: string) => {\n if (acc != null && typeof acc === 'object') {\n return (acc as Record<string, unknown>)[key];\n }\n return '';\n }, obj) as string ?? '';\n }\n\n // public static applyServerError(control: AbstractControl | null, serverError: ServerError): void {\n // if (!control) {\n // return;\n // }\n // if (control.getError(NgxValidationMessagesService.SERVER_ERRORS)) {\n // const existingErrorMessages = control.getError(NgxValidationMessagesService.SERVER_ERRORS);\n // if (_.isArray(existingErrorMessages.customMessages) &&\n // existingErrorMessages.customMessages.indexOf(serverError.message) === -1) {\n // existingErrorMessages.customMessages.push(serverError.message);\n // }\n // } else {\n // control.setErrors({[NgxValidationMessagesService.SERVER_ERRORS]: {customMessages: [serverError.message]}});\n // }\n // control.markAsTouched();\n // }\n\n}\n","import { AfterViewInit, Component, ContentChildren, ElementRef, Inject, Input, QueryList } from '@angular/core';\nimport { NgxValidatorNameDirective } from '../../directivies/ngx-validator-name.directive';\nimport {\n NGX_VALIDATION_MESSAGES_CONFIG,\n NgxValidationMessagesConfig\n} from '../../interface/ngx-validation-messages.config';\nimport { NgxValidationMessagesService } from '../../service/ngx-validation-messages.service';\nimport { NgxCustomMessageComponent } from '../ngx-custom-message/ngx-custom-message.component';\nimport { CommonModule } from '@angular/common';\nimport { MatFormFieldModule } from '@angular/material/form-field';\n\n/**\n * Component for displaying validation messages, supports child components of type {@link NgxCustomMessageComponent}\n * and html elements with directive {@link NgxValidatorNameDirective} to override validation messages.\n */\n@Component({\n standalone: true,\n selector: 'ngx-validation-messages, [ngxValidationMessages]',\n templateUrl: './ngx-validation-messages.component.html',\n styleUrls: ['./ngx-validation-messages.component.scss'],\n imports: [\n CommonModule,\n MatFormFieldModule,\n ]\n})\nexport class NgxValidationMessagesComponent implements AfterViewInit {\n\n /**\n * Form control for which need to show validation messages.\n */\n @Input('for')\n public formControl: any;\n\n /**\n * Contains {@link NgxCustomMessageComponent} if present.\n */\n @ContentChildren(NgxCustomMessageComponent)\n public customMsgComponent: any;\n\n /**\n * Contains {@link NgxValidatorNameDirective} if present.\n */\n @ContentChildren(NgxValidatorNameDirective)\n public customMsgDirective: any;\n\n public isMaterialError = false;\n\n /**\n * Key to get default validation message.\n */\n private defaultError = 'error';\n\n private materialErrorElement = 'MAT-ERROR';\n\n constructor(@Inject(NGX_VALIDATION_MESSAGES_CONFIG) public ngxValidationConfig: NgxValidationMessagesConfig,\n private ngxValidationMessagesService: NgxValidationMessagesService,\n private directiveElementRef: ElementRef) {\n }\n\n public ngAfterViewInit(): void {\n if (this.directiveElementRef && this.directiveElementRef.nativeElement\n && this.directiveElementRef.nativeElement.nodeName) {\n this.isMaterialError = this.materialErrorElement.toLocaleUpperCase()\n === this.directiveElementRef.nativeElement.nodeName.toLocaleUpperCase();\n }\n }\n\n /**\n * Get all validation messages for specified form control.\n */\n public get errorMessages(): Array<string> {\n const result: Array<string> = [];\n\n if (!this.formControl || !this.formControl.errors) {\n return result;\n }\n if (this.customMsgComponent && this.customMsgComponent.length > 0) {\n this.processingCustomMessages(this.customMsgComponent);\n }\n if (this.customMsgDirective && this.customMsgDirective.length > 0) {\n this.processingCustomMessages(this.customMsgDirective);\n }\n\n for (const property in this.formControl.errors) {\n if (this.formControl.errors.hasOwnProperty(property)\n && (this.formControl.touched || this.formControl.dirty)) {\n if (this.formControl.errors[property].customMessages instanceof Array) {\n result.push(...this.formControl.errors[property].customMessages);\n continue;\n }\n if (this.formControl.errors[property].customMessage) {\n result.push(this.formControl.errors[property].customMessage);\n continue;\n }\n const validationMessage: string =\n this.ngxValidationMessagesService.getValidatorErrorMessages(property, this.formControl.errors[property]);\n result.push(validationMessage || this.formControl.errors[property].message\n || this.ngxValidationMessagesService.getValidatorErrorMessages(this.defaultError));\n }\n }\n return result;\n }\n\n private processingCustomMessages(customMessage: QueryList<any>): void {\n customMessage.forEach((msg: any) => {\n if (!this.formControl.errors[msg.validatorName]) {\n return;\n }\n let message = (msg instanceof NgxCustomMessageComponent)\n ? msg.message?.nativeElement.innerText : msg.message;\n message = this.ngxValidationMessagesService.expandParameterizedTemplateMessage(message, this.formControl.errors[msg.validatorName]);\n\n typeof this.formControl.errors[msg.validatorName] === 'object'\n ? this.formControl.errors[msg.validatorName].customMessage = message\n : this.formControl.errors[msg.validatorName] = {customMessage: message};\n });\n }\n\n}\n","<!--To show error messages standalone without component-->\n@if (!formControl && customMsgComponent.length == 0 && customMsgDirective.length == 0) {\n <div\n [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n <ng-content></ng-content>\n </span>\n </div>\n}\n\n@if (errorMessages.length > 0) {\n <!--To show error messages in material ui style-->\n @if (isMaterialError) {\n @for (message of errorMessages; track message) {\n <mat-error>{{ message }}</mat-error>\n }\n } @else {\n <div [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n @for (message of errorMessages; track message) {\n <div>\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n {{ message }}\n </span>\n </div>\n }\n </div>\n }\n <!--To show error messages in user style-->\n}\n","import { Provider } from '@angular/core';\r\nimport {\r\n DEFAULT_CONFIG,\r\n NGX_VALIDATION_MESSAGES_CONFIG,\r\n NgxValidationMessagesConfig\r\n} from './interface/ngx-validation-messages.config';\r\n\r\nexport { NGX_VALIDATION_MESSAGES_CONFIG } from './interface/ngx-validation-messages.config';\r\nexport type { NgxValidationMessagesConfig } from './interface/ngx-validation-messages.config';\r\nexport { NgxCustomMessageComponent } from './components/ngx-custom-message/ngx-custom-message.component';\r\nexport { NgxValidationMessagesComponent } from './components/ngx-validation-messages/ngx-validation-messages.component';\r\nexport { NgxValidatorNameDirective } from './directivies/ngx-validator-name.directive';\r\n\r\nexport function provideNgxValidationMessages(config: NgxValidationMessagesConfig): Provider[] {\r\n return [\r\n {\r\n provide: NGX_VALIDATION_MESSAGES_CONFIG,\r\n useValue: config\r\n }\r\n ];\r\n}\r\n\r\nexport function provideNgxValidationMessagesTesting(config?: NgxValidationMessagesConfig): Provider[] {\r\n return [\r\n {\r\n provide: NGX_VALIDATION_MESSAGES_CONFIG,\r\n useValue: config ?? DEFAULT_CONFIG\r\n }\r\n ];\r\n}\r\n","/*\n * Public API Surface of ngx-validation-messages\n */\nexport * from './lib/ngx-validation-messages.providers';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.NgxValidationMessagesService"],"mappings":";;;;;;;MAEa,8BAA8B,GACvC,IAAI,cAAc,CAA8B,6BAA6B;AAqB1E,MAAM,cAAc,GAAgC;AACzD,IAAA,QAAQ,EAAE;CACX;;ACvBD;;;;;AAKG;MAUU,yBAAyB,CAAA;AAEpC;;AAEG;AAEI,IAAA,aAAa;AAEpB;;AAEG;AAEI,IAAA,OAAO;uGAZH,yBAAyB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,e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BA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"lagoshny-ngx-validation-messages.mjs","sources":["../../../projects/ngx-validation-messages/src/lib/interface/ngx-validation-messages.config.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-custom-message/ngx-custom-message.component.ts","../../../projects/ngx-validation-messages/src/lib/service/ngx-validation-messages.service.ts","../../../projects/ngx-validation-messages/src/lib/directivies/ngx-validator-name.directive.ts","../../../projects/ngx-validation-messages/src/lib/components/base/ngx-validation-messages-base.directive.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-mat-validation-messages/ngx-mat-validation-messages.directive.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-validation-messages/ngx-validation-messages.component.ts","../../../projects/ngx-validation-messages/src/lib/components/ngx-validation-messages/ngx-validation-messages.component.html","../../../projects/ngx-validation-messages/src/lib/ngx-validation-messages.providers.ts","../../../projects/ngx-validation-messages/src/public-api.ts","../../../projects/ngx-validation-messages/src/lagoshny-ngx-validation-messages.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport const NGX_VALIDATION_MESSAGES_CONFIG: InjectionToken<NgxValidationMessagesConfig>\n = new InjectionToken<NgxValidationMessagesConfig>('NgxValidationMessagesConfig');\n\nexport interface NgxValidationMessagesConfig {\n\n /**\n * Object contains validation messages in validatorName: validatorMessage format.\n */\n messages: {\n [validatorName: string]: string;\n };\n\n /**\n * Define custom styles to display validation messages.\n */\n validationMessagesStyle?: {\n blockClassNames?: string;\n textClassNames?: string;\n };\n\n}\n\nexport const DEFAULT_CONFIG: NgxValidationMessagesConfig = {\n messages: {}\n}\n","import { Component, ElementRef, Input, ViewChild } from '@angular/core';\n\n\n/**\n * Component allows specifying custom validation message for the specified\n * validator to override default message.\n *\n * Use this component as child in {@link NgxValidationMessagesComponent}.\n */\n@Component({\n standalone: true,\n selector: 'ngx-custom-message',\n template: `\n <div #message>\n <ng-content></ng-content>\n </div>`,\n imports: []\n})\nexport class NgxCustomMessageComponent {\n\n /**\n * The name of the validator for which you want to override the message.\n */\n @Input('forValidator')\n public validatorName: string | undefined;\n\n /**\n * Contains overridden message for validator.\n */\n @ViewChild('message')\n public message: ElementRef | undefined;\n\n}\n","import { inject, Injectable } from '@angular/core';\nimport {\n NGX_VALIDATION_MESSAGES_CONFIG,\n NgxValidationMessagesConfig\n} from '../interface/ngx-validation-messages.config';\n\n/**\n * Service allows getting validation messages from client's settings.\n * Injecting {@link NgxValidationMessagesConfig} to get client's configuration with validation messages.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class NgxValidationMessagesService {\n\n public static SERVER_ERRORS = 'serverErrors';\n\n /**\n * Regular expression to find params placeholder '#[paramName]'.\n */\n private paramsRegExp = new RegExp(/#[[a-zA-Z_\\\\-]*]/);\n\n private readonly messagesConfig: NgxValidationMessagesConfig = inject(\n NGX_VALIDATION_MESSAGES_CONFIG,\n );\n\n /**\n * Get validation message for specified validator.\n *\n * @param validatorName for which to get message\n * @param params passed from validator for more detailed validation message\n *\n * @returns string validation message\n */\n public getValidatorErrorMessages(validatorName: string, params?: object): string {\n const validationMessages = this.messagesConfig.messages;\n const validationMessage: string = validationMessages[validatorName];\n\n if (!validationMessage) {\n throw new Error('Validation message for validator: ' + validatorName\n + ' cannot be found, please check validation message key for validator it is case sensitive.');\n }\n\n if (params) {\n return this.expandParameterizedTemplateMessage(validationMessage, params);\n }\n\n return validationMessage;\n }\n\n public expandParameterizedTemplateMessage(msg: string, params: object): string {\n while (this.paramsRegExp.test(msg)) {\n const foundParams = this.paramsRegExp.exec(msg);\n foundParams?.forEach(value => {\n const paramPlaceholder = value;\n value = value.replace('#[', '').replace(']', '');\n msg = msg.replace(paramPlaceholder, this.getParameter(params, value));\n });\n }\n\n return msg;\n }\n\n /**\n * A utilitarian method to get a property from an object.\n * if there is no property, an empty string is returned.\n *\n * @param obj from which the property must be obtained\n * @param prop property name\n *\n * @return property value or empty string\n */\n private getParameter(obj: unknown, prop: string): string {\n return prop.split('.').reduce((acc: unknown, key: string) => {\n if (acc != null && typeof acc === 'object') {\n return (acc as Record<string, unknown>)[key];\n }\n return '';\n }, obj) as string ?? '';\n }\n\n // public static applyServerError(control: AbstractControl | null, serverError: ServerError): void {\n // if (!control) {\n // return;\n // }\n // if (control.getError(NgxValidationMessagesService.SERVER_ERRORS)) {\n // const existingErrorMessages = control.getError(NgxValidationMessagesService.SERVER_ERRORS);\n // if (_.isArray(existingErrorMessages.customMessages) &&\n // existingErrorMessages.customMessages.indexOf(serverError.message) === -1) {\n // existingErrorMessages.customMessages.push(serverError.message);\n // }\n // } else {\n // control.setErrors({[NgxValidationMessagesService.SERVER_ERRORS]: {customMessages: [serverError.message]}});\n // }\n // control.markAsTouched();\n // }\n\n}\n","import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';\n\n/**\n * Allows to specify custom validator message to override default message.\n *\n * It's alternative for {@link NgxCustomMessageComponent}.\n * If you want to use standard html tags to define custom message, use this directive on html tag within\n * {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,\n * otherwise use {@link NgxCustomMessageComponent}.\n */\n@Directive({\n standalone: true,\n selector: '[ngxValidatorName]'\n})\nexport class NgxValidatorNameDirective implements AfterViewInit {\n\n /**\n * The name of the validator for which you want to override the message.\n */\n @Input()\n public validatorName: string | undefined;\n\n /**\n * Contains overridden message for validator.\n */\n public message: string | undefined;\n\n constructor(private elem: ElementRef) {\n }\n\n public ngAfterViewInit(): void {\n this.message = this.elem.nativeElement.innerText;\n }\n\n}\n","import { ContentChildren, Directive, inject, Input, QueryList } from '@angular/core';\nimport { AbstractControl } from '@angular/forms';\nimport {\n NGX_VALIDATION_MESSAGES_CONFIG,\n NgxValidationMessagesConfig\n} from '../../interface/ngx-validation-messages.config';\nimport { NgxValidationMessagesService } from '../../service/ngx-validation-messages.service';\nimport { NgxValidatorNameDirective } from '../../directivies/ngx-validator-name.directive';\nimport { NgxCustomMessageComponent } from '../ngx-custom-message/ngx-custom-message.component';\n\n@Directive()\nexport abstract class NgxValidationMessagesBase {\n /**\n * Form control for which need to show validation messages.\n */\n @Input('for')\n public formControl: AbstractControl | null = null;\n\n /**\n * Contains {@link NgxCustomMessageComponent} if present.\n */\n @ContentChildren(NgxCustomMessageComponent)\n public customMsgComponent!: QueryList<NgxCustomMessageComponent>;\n\n /**\n * Contains {@link NgxValidatorNameDirective} if present.\n */\n @ContentChildren(NgxValidatorNameDirective)\n public customMsgDirective!: QueryList<NgxValidatorNameDirective>;\n\n /**\n * Key to get default validation message.\n */\n private defaultError = 'error';\n\n readonly ngxValidationConfig: NgxValidationMessagesConfig = inject(\n NGX_VALIDATION_MESSAGES_CONFIG,\n );\n\n private readonly ngxValidationMessagesService = inject(NgxValidationMessagesService);\n\n /**\n * Get all validation messages for specified form control.\n */\n public get errorMessages(): Array<string> {\n const result: Array<string> = [];\n\n if (!this.formControl?.errors || !(this.formControl.touched || this.formControl.dirty)) {\n return result;\n }\n if (this.customMsgComponent && this.customMsgComponent.length > 0) {\n this.processingCustomMessages(this.customMsgComponent);\n }\n if (this.customMsgDirective && this.customMsgDirective.length > 0) {\n this.processingCustomMessages(this.customMsgDirective);\n }\n\n for (const property in this.formControl.errors) {\n if (this.formControl.errors.hasOwnProperty(property)\n && (this.formControl.touched || this.formControl.dirty)) {\n if (this.formControl.errors[property].customMessages instanceof Array) {\n result.push(...this.formControl.errors[property].customMessages);\n continue;\n }\n if (this.formControl.errors[property].customMessage) {\n result.push(this.formControl.errors[property].customMessage);\n continue;\n }\n const validationMessage: string =\n this.ngxValidationMessagesService.getValidatorErrorMessages(property, this.formControl.errors[property]);\n result.push(validationMessage || this.formControl.errors[property].message\n || this.ngxValidationMessagesService.getValidatorErrorMessages(this.defaultError));\n }\n }\n return result;\n }\n\n private processingCustomMessages(customMessage: QueryList<any>): void {\n customMessage.forEach((msg: any) => {\n if (this.formControl == null || !this.formControl?.errors || !this.formControl.errors[msg.validatorName]) {\n return;\n }\n let message = (msg instanceof NgxCustomMessageComponent)\n ? msg.message?.nativeElement.innerText : msg.message;\n message = this.ngxValidationMessagesService.expandParameterizedTemplateMessage(message, this.formControl.errors[msg.validatorName]);\n\n typeof this.formControl.errors[msg.validatorName] === 'object'\n ? this.formControl.errors[msg.validatorName].customMessage = message\n : this.formControl.errors[msg.validatorName] = { customMessage: message };\n });\n }\n\n}\n","import { Directive, DoCheck, ElementRef, inject, OnDestroy, Renderer2 } from '@angular/core';\nimport { NgxValidationMessagesBase } from '../base/ngx-validation-messages-base.directive';\n\n/**\n * Attribute directive for Material form fields.\n * Usage: <mat-error ngxValidationMessages [for]=\"form.get('email')\"></mat-error>\n */\n@Directive({\n standalone: true,\n selector: 'mat-error[ngxValidationMessages]'\n})\nexport class NgxMatValidationMessagesDirective extends NgxValidationMessagesBase implements DoCheck, OnDestroy {\n private readonly hostElementRef = inject(ElementRef<HTMLElement>);\n private readonly renderer = inject(Renderer2);\n private renderedMessages: string[] = [];\n private dynamicMessageElements: HTMLElement[] = [];\n\n public ngDoCheck(): void {\n if (!this.formControl) {\n this.resetRenderedMessages();\n return;\n }\n\n const currentMessages = this.errorMessages;\n if (this.isEqualMessageSet(this.renderedMessages, currentMessages)) {\n return;\n }\n\n this.renderedMessages = [...currentMessages];\n this.renderMessages(currentMessages);\n }\n\n public ngOnDestroy(): void {\n this.resetRenderedMessages();\n }\n\n private renderMessages(messages: string[]): void {\n const hostElement = this.hostElementRef.nativeElement;\n this.renderer.setProperty(hostElement, 'textContent', messages[0] ?? '');\n this.syncAdditionalMessageElements(messages.slice(1));\n }\n\n private syncAdditionalMessageElements(messages: string[]): void {\n while (this.dynamicMessageElements.length < messages.length) {\n this.dynamicMessageElements.push(this.createDynamicMatErrorElement());\n }\n\n while (this.dynamicMessageElements.length > messages.length) {\n const errorElement = this.dynamicMessageElements.pop();\n if (errorElement?.parentNode) {\n this.renderer.removeChild(errorElement.parentNode, errorElement);\n }\n }\n\n const hostElement = this.hostElementRef.nativeElement;\n const parentElement = hostElement.parentNode;\n\n let previousNode: Node = hostElement;\n this.dynamicMessageElements.forEach((errorElement, index) => {\n this.renderer.setProperty(errorElement, 'textContent', messages[index]);\n\n if (!parentElement) {\n return;\n }\n\n this.renderer.insertBefore(parentElement, errorElement, previousNode.nextSibling);\n previousNode = errorElement;\n });\n }\n\n private createDynamicMatErrorElement(): HTMLElement {\n const errorElement = this.renderer.createElement('mat-error') as HTMLElement;\n const hostClasses = this.hostElementRef.nativeElement.className;\n if (hostClasses) {\n this.renderer.setAttribute(errorElement, 'class', hostClasses);\n }\n return errorElement;\n }\n\n private destroyDynamicMessageElements(): void {\n this.dynamicMessageElements.forEach((errorElement) => {\n if (errorElement.parentNode) {\n this.renderer.removeChild(errorElement.parentNode, errorElement);\n }\n });\n this.dynamicMessageElements = [];\n }\n\n private resetRenderedMessages(): void {\n if (this.renderedMessages.length === 0 && this.dynamicMessageElements.length === 0) {\n return;\n }\n this.renderedMessages = [];\n this.renderer.setProperty(this.hostElementRef.nativeElement, 'textContent', '');\n this.destroyDynamicMessageElements();\n }\n\n private isEqualMessageSet(previous: string[], current: string[]): boolean {\n if (previous.length !== current.length) {\n return false;\n }\n return previous.every((message, index) => message === current[index]);\n }\n}\n","import { Component } from '@angular/core';\nimport { NgxValidatorNameDirective } from '../../directivies/ngx-validator-name.directive';\nimport { NgxCustomMessageComponent } from '../ngx-custom-message/ngx-custom-message.component';\nimport { CommonModule } from '@angular/common';\nimport { NgxValidationMessagesBase } from '../base/ngx-validation-messages-base.directive';\n\n/**\n * Component for displaying validation messages, supports child components of type {@link NgxCustomMessageComponent}\n * and html elements with directive {@link NgxValidatorNameDirective} to override validation messages.\n */\n@Component({\n standalone: true,\n selector: 'ngx-validation-messages',\n templateUrl: './ngx-validation-messages.component.html',\n styleUrls: ['./ngx-validation-messages.component.scss'],\n imports: [\n CommonModule,\n ]\n})\nexport class NgxValidationMessagesComponent extends NgxValidationMessagesBase {}\n","<!--To show error messages standalone without component-->\n@if (!formControl && customMsgComponent.length == 0 && customMsgDirective.length == 0) {\n <div\n [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n <ng-content></ng-content>\n </span>\n </div>\n}\n\n@if (errorMessages.length > 0) {\n <div [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.blockClassNames || 'ngx_vm__def_error_block'\">\n @for (message of errorMessages; track message) {\n <div>\n <span [ngClass]=\"ngxValidationConfig?.validationMessagesStyle?.textClassNames || 'ngx_vm__def_error_text'\">\n {{ message }}\n </span>\n </div>\n }\n </div>\n}\n","import { Provider } from '@angular/core';\nimport {\n DEFAULT_CONFIG,\n NGX_VALIDATION_MESSAGES_CONFIG,\n NgxValidationMessagesConfig\n} from './interface/ngx-validation-messages.config';\n\nexport { NGX_VALIDATION_MESSAGES_CONFIG } from './interface/ngx-validation-messages.config';\nexport type { NgxValidationMessagesConfig } from './interface/ngx-validation-messages.config';\nexport { NgxCustomMessageComponent } from './components/ngx-custom-message/ngx-custom-message.component';\nexport { NgxMatValidationMessagesDirective } from './components/ngx-mat-validation-messages/ngx-mat-validation-messages.directive';\nexport { NgxValidationMessagesComponent } from './components/ngx-validation-messages/ngx-validation-messages.component';\nexport { NgxValidatorNameDirective } from './directivies/ngx-validator-name.directive';\n\nexport function provideNgxValidationMessages(config: NgxValidationMessagesConfig): Provider[] {\n return [\n {\n provide: NGX_VALIDATION_MESSAGES_CONFIG,\n useValue: config\n }\n ];\n}\n\nexport function provideNgxValidationMessagesTesting(config?: NgxValidationMessagesConfig): Provider[] {\n return [\n {\n provide: NGX_VALIDATION_MESSAGES_CONFIG,\n useValue: config ?? DEFAULT_CONFIG\n }\n ];\n}\n","/*\n * Public API Surface of ngx-validation-messages\n */\nexport * from './lib/ngx-validation-messages.providers';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAEa,8BAA8B,GACvC,IAAI,cAAc,CAA8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A,EAAA,MAAA,EAAA,CAAA,OAAA,EAAA,SAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;2FAGP,8BAA8B,EAAA,UAAA,EAAA,CAAA;kBAT1C,SAAS;iCACI,IAAI,EAAA,QAAA,EACN,yBAAyB,EAAA,OAAA,EAGxB;wBACL,YAAY;AACf,qBAAA,EAAA,QAAA,EAAA,+1BAAA,EAAA,MAAA,EAAA,CAAA,0OAAA,CAAA,EAAA;;;AEHC,SAAU,4BAA4B,CAAC,MAAmC,EAAA;IAC9E,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,8BAA8B;AACvC,YAAA,QAAQ,EAAE;AACX;KACF;AACH;AAEM,SAAU,mCAAmC,CAAC,MAAoC,EAAA;IACtF,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,8BAA8B;YACvC,QAAQ,EAAE,MAAM,IAAI;AACrB;KACF;AACH;;AC9BA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lagoshny/ngx-validation-messages",
|
|
3
|
-
"version": "21.0
|
|
3
|
+
"version": "21.1.0",
|
|
4
4
|
"description": "This module allows to simplify display form validator validation messages using single component.",
|
|
5
5
|
"readme": "README.md",
|
|
6
6
|
"author": "Ilya Lagoshny <ilya@lagoshny.ru>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"@angular/common": ">=12.x.x",
|
|
10
|
-
"@angular/core": ">=12.x.x"
|
|
10
|
+
"@angular/core": ">=12.x.x",
|
|
11
|
+
"@angular/material": ">=12.x.x"
|
|
12
|
+
},
|
|
13
|
+
"peerDependenciesMeta": {
|
|
14
|
+
"@angular/material": {
|
|
15
|
+
"optional": true
|
|
16
|
+
}
|
|
11
17
|
},
|
|
12
18
|
"keywords": [
|
|
13
19
|
"Angular validation",
|
|
@@ -54,5 +60,6 @@
|
|
|
54
60
|
"types": "./types/lagoshny-ngx-validation-messages.d.ts",
|
|
55
61
|
"default": "./fesm2022/lagoshny-ngx-validation-messages.mjs"
|
|
56
62
|
}
|
|
57
|
-
}
|
|
63
|
+
},
|
|
64
|
+
"type": "module"
|
|
58
65
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, ElementRef, AfterViewInit, Provider } from '@angular/core';
|
|
2
|
+
import { InjectionToken, ElementRef, AfterViewInit, QueryList, DoCheck, OnDestroy, Provider } from '@angular/core';
|
|
3
|
+
import { AbstractControl } from '@angular/forms';
|
|
3
4
|
|
|
4
5
|
declare const NGX_VALIDATION_MESSAGES_CONFIG: InjectionToken<NgxValidationMessagesConfig>;
|
|
5
6
|
interface NgxValidationMessagesConfig {
|
|
@@ -38,104 +39,89 @@ declare class NgxCustomMessageComponent {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* Allows to specify custom validator message to override default message.
|
|
43
|
+
*
|
|
44
|
+
* It's alternative for {@link NgxCustomMessageComponent}.
|
|
45
|
+
* If you want to use standard html tags to define custom message, use this directive on html tag within
|
|
46
|
+
* {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,
|
|
47
|
+
* otherwise use {@link NgxCustomMessageComponent}.
|
|
43
48
|
*/
|
|
44
|
-
declare class
|
|
45
|
-
private
|
|
46
|
-
static SERVER_ERRORS: string;
|
|
47
|
-
/**
|
|
48
|
-
* Regular expression to find params placeholder '#[paramName]'.
|
|
49
|
-
*/
|
|
50
|
-
private paramsRegExp;
|
|
51
|
-
constructor(messagesConfig: NgxValidationMessagesConfig);
|
|
49
|
+
declare class NgxValidatorNameDirective implements AfterViewInit {
|
|
50
|
+
private elem;
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param validatorName for which to get message
|
|
56
|
-
* @param params passed from validator for more detailed validation message
|
|
57
|
-
*
|
|
58
|
-
* @returns string validation message
|
|
52
|
+
* The name of the validator for which you want to override the message.
|
|
59
53
|
*/
|
|
60
|
-
|
|
61
|
-
expandParameterizedTemplateMessage(msg: string, params: object): string;
|
|
54
|
+
validatorName: string | undefined;
|
|
62
55
|
/**
|
|
63
|
-
*
|
|
64
|
-
* if there is no property, an empty string is returned.
|
|
65
|
-
*
|
|
66
|
-
* @param obj from which the property must be obtained
|
|
67
|
-
* @param prop property name
|
|
68
|
-
*
|
|
69
|
-
* @return property value or empty string
|
|
56
|
+
* Contains overridden message for validator.
|
|
70
57
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
message: string | undefined;
|
|
59
|
+
constructor(elem: ElementRef);
|
|
60
|
+
ngAfterViewInit(): void;
|
|
61
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxValidatorNameDirective, never>;
|
|
62
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<NgxValidatorNameDirective, "[ngxValidatorName]", never, { "validatorName": { "alias": "validatorName"; "required": false; }; }, {}, never, never, true, never>;
|
|
74
63
|
}
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
* Component for displaying validation messages, supports child components of type {@link NgxCustomMessageComponent}
|
|
78
|
-
* and html elements with directive {@link NgxValidatorNameDirective} to override validation messages.
|
|
79
|
-
*/
|
|
80
|
-
declare class NgxValidationMessagesComponent implements AfterViewInit {
|
|
81
|
-
ngxValidationConfig: NgxValidationMessagesConfig;
|
|
82
|
-
private ngxValidationMessagesService;
|
|
83
|
-
private directiveElementRef;
|
|
65
|
+
declare abstract class NgxValidationMessagesBase {
|
|
84
66
|
/**
|
|
85
67
|
* Form control for which need to show validation messages.
|
|
86
68
|
*/
|
|
87
|
-
formControl:
|
|
69
|
+
formControl: AbstractControl | null;
|
|
88
70
|
/**
|
|
89
71
|
* Contains {@link NgxCustomMessageComponent} if present.
|
|
90
72
|
*/
|
|
91
|
-
customMsgComponent:
|
|
73
|
+
customMsgComponent: QueryList<NgxCustomMessageComponent>;
|
|
92
74
|
/**
|
|
93
75
|
* Contains {@link NgxValidatorNameDirective} if present.
|
|
94
76
|
*/
|
|
95
|
-
customMsgDirective:
|
|
96
|
-
isMaterialError: boolean;
|
|
77
|
+
customMsgDirective: QueryList<NgxValidatorNameDirective>;
|
|
97
78
|
/**
|
|
98
79
|
* Key to get default validation message.
|
|
99
80
|
*/
|
|
100
81
|
private defaultError;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
ngAfterViewInit(): void;
|
|
82
|
+
readonly ngxValidationConfig: NgxValidationMessagesConfig;
|
|
83
|
+
private readonly ngxValidationMessagesService;
|
|
104
84
|
/**
|
|
105
85
|
* Get all validation messages for specified form control.
|
|
106
86
|
*/
|
|
107
87
|
get errorMessages(): Array<string>;
|
|
108
88
|
private processingCustomMessages;
|
|
109
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<
|
|
110
|
-
static
|
|
89
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxValidationMessagesBase, never>;
|
|
90
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<NgxValidationMessagesBase, never, never, { "formControl": { "alias": "for"; "required": false; }; }, {}, ["customMsgComponent", "customMsgDirective"], never, true, never>;
|
|
111
91
|
}
|
|
112
92
|
|
|
113
93
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* It's alternative for {@link NgxCustomMessageComponent}.
|
|
117
|
-
* If you want to use standard html tags to define custom message, use this directive on html tag within
|
|
118
|
-
* {@link NgxValidationMessagesComponent} specifying validator name as directive parameter,
|
|
119
|
-
* otherwise use {@link NgxCustomMessageComponent}.
|
|
94
|
+
* Attribute directive for Material form fields.
|
|
95
|
+
* Usage: <mat-error ngxValidationMessages [for]="form.get('email')"></mat-error>
|
|
120
96
|
*/
|
|
121
|
-
declare class
|
|
122
|
-
private
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
static
|
|
97
|
+
declare class NgxMatValidationMessagesDirective extends NgxValidationMessagesBase implements DoCheck, OnDestroy {
|
|
98
|
+
private readonly hostElementRef;
|
|
99
|
+
private readonly renderer;
|
|
100
|
+
private renderedMessages;
|
|
101
|
+
private dynamicMessageElements;
|
|
102
|
+
ngDoCheck(): void;
|
|
103
|
+
ngOnDestroy(): void;
|
|
104
|
+
private renderMessages;
|
|
105
|
+
private syncAdditionalMessageElements;
|
|
106
|
+
private createDynamicMatErrorElement;
|
|
107
|
+
private destroyDynamicMessageElements;
|
|
108
|
+
private resetRenderedMessages;
|
|
109
|
+
private isEqualMessageSet;
|
|
110
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxMatValidationMessagesDirective, never>;
|
|
111
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<NgxMatValidationMessagesDirective, "mat-error[ngxValidationMessages]", never, {}, {}, never, never, true, never>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Component for displaying validation messages, supports child components of type {@link NgxCustomMessageComponent}
|
|
116
|
+
* and html elements with directive {@link NgxValidatorNameDirective} to override validation messages.
|
|
117
|
+
*/
|
|
118
|
+
declare class NgxValidationMessagesComponent extends NgxValidationMessagesBase {
|
|
119
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxValidationMessagesComponent, never>;
|
|
120
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<NgxValidationMessagesComponent, "ngx-validation-messages", never, {}, {}, never, ["*"], true, never>;
|
|
135
121
|
}
|
|
136
122
|
|
|
137
123
|
declare function provideNgxValidationMessages(config: NgxValidationMessagesConfig): Provider[];
|
|
138
124
|
declare function provideNgxValidationMessagesTesting(config?: NgxValidationMessagesConfig): Provider[];
|
|
139
125
|
|
|
140
|
-
export { NGX_VALIDATION_MESSAGES_CONFIG, NgxCustomMessageComponent, NgxValidationMessagesComponent, NgxValidatorNameDirective, provideNgxValidationMessages, provideNgxValidationMessagesTesting };
|
|
126
|
+
export { NGX_VALIDATION_MESSAGES_CONFIG, NgxCustomMessageComponent, NgxMatValidationMessagesDirective, NgxValidationMessagesComponent, NgxValidatorNameDirective, provideNgxValidationMessages, provideNgxValidationMessagesTesting };
|
|
141
127
|
export type { NgxValidationMessagesConfig };
|