@acorex/components 7.17.21 → 7.17.23
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/check-box/lib/check-box.component.d.ts +3 -3
- package/common/lib/classes/components.class.d.ts +11 -0
- package/common/lib/components/value-component.class.d.ts +10 -4
- package/data-table/lib/data-table.component.d.ts +1 -1
- package/datetime-box/lib/datetime-box.component.d.ts +1 -1
- package/esm2022/calendar/lib/calendar-range.component.mjs +1 -2
- package/esm2022/calendar/lib/calendar.component.mjs +10 -2
- package/esm2022/check-box/lib/check-box.component.mjs +9 -4
- package/esm2022/color-palette/lib/color-palette.component.mjs +4 -2
- package/esm2022/common/lib/classes/components.class.mjs +1 -1
- package/esm2022/common/lib/components/value-component.class.mjs +38 -65
- package/esm2022/data-pager/lib/data-pager.component.mjs +1 -2
- package/esm2022/data-table/lib/data-table.component.mjs +6 -4
- package/esm2022/datetime-box/lib/datetime-box.component.mjs +5 -4
- package/esm2022/dialog/lib/dialog.module.mjs +4 -4
- package/esm2022/form/index.mjs +2 -3
- package/esm2022/form/lib/form-field.component.mjs +34 -6
- package/esm2022/form/lib/form.component.mjs +44 -86
- package/esm2022/form/lib/form.config.mjs +3 -23
- package/esm2022/form/lib/form.module.mjs +9 -8
- package/esm2022/form/lib/validation-rule.directive.mjs +33 -0
- package/esm2022/form/lib/validation-summary.component.mjs +19 -13
- package/esm2022/label/lib/label.component.mjs +21 -10
- package/esm2022/number-box/lib/number-box.component.mjs +8 -3
- package/esm2022/otp/lib/otp.component.mjs +1 -1
- package/esm2022/password-box/lib/password-box.component.mjs +4 -2
- package/esm2022/radio/lib/radio.component.mjs +2 -2
- package/esm2022/select-box/lib/select-box.component.mjs +1 -2
- package/esm2022/selection-list/lib/selection-list.component.mjs +8 -8
- package/fesm2022/acorex-components-calendar.mjs +9 -2
- package/fesm2022/acorex-components-calendar.mjs.map +1 -1
- package/fesm2022/acorex-components-check-box.mjs +8 -3
- package/fesm2022/acorex-components-check-box.mjs.map +1 -1
- package/fesm2022/acorex-components-color-palette.mjs +3 -1
- package/fesm2022/acorex-components-color-palette.mjs.map +1 -1
- package/fesm2022/acorex-components-common.mjs +36 -63
- package/fesm2022/acorex-components-common.mjs.map +1 -1
- package/fesm2022/acorex-components-data-pager.mjs +0 -1
- package/fesm2022/acorex-components-data-pager.mjs.map +1 -1
- package/fesm2022/acorex-components-data-table.mjs +4 -2
- package/fesm2022/acorex-components-data-table.mjs.map +1 -1
- package/fesm2022/acorex-components-datetime-box.mjs +4 -3
- package/fesm2022/acorex-components-datetime-box.mjs.map +1 -1
- package/fesm2022/acorex-components-dialog.mjs +3 -3
- package/fesm2022/acorex-components-dialog.mjs.map +1 -1
- package/fesm2022/acorex-components-form.mjs +135 -250
- package/fesm2022/acorex-components-form.mjs.map +1 -1
- package/fesm2022/acorex-components-label.mjs +19 -8
- package/fesm2022/acorex-components-label.mjs.map +1 -1
- package/fesm2022/acorex-components-number-box.mjs +7 -2
- package/fesm2022/acorex-components-number-box.mjs.map +1 -1
- package/fesm2022/acorex-components-otp.mjs.map +1 -1
- package/fesm2022/acorex-components-password-box.mjs +3 -1
- package/fesm2022/acorex-components-password-box.mjs.map +1 -1
- package/fesm2022/acorex-components-radio.mjs +1 -1
- package/fesm2022/acorex-components-radio.mjs.map +1 -1
- package/fesm2022/acorex-components-select-box.mjs +0 -1
- package/fesm2022/acorex-components-select-box.mjs.map +1 -1
- package/fesm2022/acorex-components-selection-list.mjs +6 -6
- package/fesm2022/acorex-components-selection-list.mjs.map +1 -1
- package/form/index.d.ts +1 -2
- package/form/lib/form-field.component.d.ts +8 -2
- package/form/lib/form.component.d.ts +9 -13
- package/form/lib/form.config.d.ts +0 -10
- package/form/lib/form.module.d.ts +3 -2
- package/form/lib/validation-rule.directive.d.ts +16 -0
- package/form/lib/validation-summary.component.d.ts +8 -5
- package/label/lib/label.component.d.ts +6 -6
- package/package.json +1 -1
- package/selection-list/lib/selection-list.component.d.ts +2 -2
- package/esm2022/form/lib/validation-rule.widget.mjs +0 -124
- package/esm2022/form/lib/validation.class.mjs +0 -2
- package/form/lib/validation-rule.widget.d.ts +0 -23
- package/form/lib/validation.class.d.ts +0 -18
@@ -1,10 +1,9 @@
|
|
1
|
-
import * as i1 from '@acorex/components/common';
|
2
|
-
import { MXBaseComponent,
|
1
|
+
import * as i1$1 from '@acorex/components/common';
|
2
|
+
import { MXBaseComponent, AXValuableComponent, AXEvent } from '@acorex/components/common';
|
3
|
+
import { AXLabelComponent } from '@acorex/components/label';
|
4
|
+
import { AXUnsubscriber } from '@acorex/core/utils';
|
3
5
|
import * as i0 from '@angular/core';
|
4
|
-
import { Component, ViewEncapsulation, ChangeDetectionStrategy, EventEmitter, Input, Output,
|
5
|
-
import { AX_GLOBAL_CONFIG } from '@acorex/core/config';
|
6
|
-
import { AXTranslator } from '@acorex/core/translation';
|
7
|
-
import { set } from 'lodash-es';
|
6
|
+
import { inject, Component, ViewEncapsulation, ChangeDetectionStrategy, ContentChild, EventEmitter, Input, Output, ContentChildren, InjectionToken, Optional, Inject, Directive, NgModule } from '@angular/core';
|
8
7
|
import * as i4 from '@acorex/components/alert';
|
9
8
|
import { AXAlertModule } from '@acorex/components/alert';
|
10
9
|
import * as i5 from '@acorex/components/button';
|
@@ -13,16 +12,44 @@ import * as i3 from '@acorex/components/decorators';
|
|
13
12
|
import { AXDecoratorModule } from '@acorex/components/decorators';
|
14
13
|
import * as i2 from '@angular/common';
|
15
14
|
import { CommonModule } from '@angular/common';
|
16
|
-
import * as i1
|
15
|
+
import * as i1 from '@acorex/components/toast';
|
16
|
+
import { AXTranslator } from '@acorex/core/translation';
|
17
|
+
import { AXValidationModule } from '@acorex/core/validation';
|
17
18
|
|
18
19
|
class AXFormFieldComponent extends MXBaseComponent {
|
20
|
+
constructor() {
|
21
|
+
super(...arguments);
|
22
|
+
this.unsubscriber = inject(AXUnsubscriber);
|
23
|
+
}
|
24
|
+
ngAfterContentInit() {
|
25
|
+
this.autoSetRequired();
|
26
|
+
this.input?.validationRulesChange
|
27
|
+
.pipe(this.unsubscriber.takeUntilDestroy)
|
28
|
+
.subscribe(() => {
|
29
|
+
this.autoSetRequired();
|
30
|
+
});
|
31
|
+
}
|
32
|
+
autoSetRequired() {
|
33
|
+
if (this.label && this.input) {
|
34
|
+
if (this.label.required == null || this.label['autoSetRequired']) {
|
35
|
+
this.label.required = this.input.isRequired;
|
36
|
+
this.label['autoSetRequired'] = true;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
19
40
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormFieldComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
20
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXFormFieldComponent, selector: "ax-form-field", usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, styles: [".ax-dark ax-form.ax-form-normal .ax-error-message{border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-200));color:rgba(var(--ax-color-danger-fore-tint))}.ax-dark ax-form.ax-form-normal .ax-error-message:before,.ax-dark ax-form.ax-form-normal .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form.ax-form-normal .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form form.ax-float-error .ax-error-message{border-color:rgba(var(--ax-color-danger-700));background-color:rgba(var(--ax-color-danger-700));color:rgba(var(--ax-color-danger-fore))}.ax-dark ax-form form.ax-float-error .ax-error-message:before,.ax-dark ax-form form.ax-float-error .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-700))}.ax-dark ax-form form.ax-float-error .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-700))}ax-form-field{position:relative;display:block;width:100%}ax-form-field .ax-error-message{margin-top:.25rem;margin-bottom:.25rem;display:block;font-size:.75rem;line-height:1rem}ax-form{width:100%}ax-form form.ax-bottom-error .ax-error-message{color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message{position:absolute;bottom:-2.5rem;z-index:10;display:block;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;border-radius:.375rem;border-width:1px;border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-500));padding:.25rem .5rem;font-weight:400;color:rgba(var(--ax-color-danger-fore))}ax-form form.ax-float-error .ax-error-message:before,ax-form form.ax-float-error .ax-error-message:after{pointer-events:none;position:absolute;bottom:100%;inset-inline-start:.75rem;z-index:20;height:0px;width:0px;border-bottom-color:rgba(var(--ax-color-danger-500));border-inline-end-color:transparent;border-inline-start-color:transparent;border-top-color:transparent;content:\"\"}ax-form form.ax-float-error .ax-error-message:before{-webkit-margin-start:-1px;margin-inline-start:-1px;border-width:4px;border-bottom-color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message:after{border-width:4px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
41
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXFormFieldComponent, selector: "ax-form-field", providers: [AXUnsubscriber], queries: [{ propertyName: "input", first: true, predicate: AXValuableComponent, descendants: true }, { propertyName: "label", first: true, predicate: AXLabelComponent, descendants: true }], usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, styles: [".ax-dark ax-form.ax-form-normal .ax-error-message{border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-200));color:rgba(var(--ax-color-danger-fore-tint))}.ax-dark ax-form.ax-form-normal .ax-error-message:before,.ax-dark ax-form.ax-form-normal .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form.ax-form-normal .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form form.ax-float-error .ax-error-message{border-color:rgba(var(--ax-color-danger-700));background-color:rgba(var(--ax-color-danger-700));color:rgba(var(--ax-color-danger-fore))}.ax-dark ax-form form.ax-float-error .ax-error-message:before,.ax-dark ax-form form.ax-float-error .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-700))}.ax-dark ax-form form.ax-float-error .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-700))}ax-form-field{position:relative;display:block;width:100%}ax-form-field .ax-error-message{margin-top:.25rem;margin-bottom:.25rem;display:block;font-size:.75rem;line-height:1rem}ax-form{width:100%}ax-form form.ax-bottom-error .ax-error-message{color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message{position:absolute;bottom:-2.5rem;z-index:10;display:block;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;border-radius:.375rem;border-width:1px;border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-500));padding:.25rem .5rem;font-weight:400;color:rgba(var(--ax-color-danger-fore))}ax-form form.ax-float-error .ax-error-message:before,ax-form form.ax-float-error .ax-error-message:after{pointer-events:none;position:absolute;bottom:100%;inset-inline-start:.75rem;z-index:20;height:0px;width:0px;border-bottom-color:rgba(var(--ax-color-danger-500));border-inline-end-color:transparent;border-inline-start-color:transparent;border-top-color:transparent;content:\"\"}ax-form form.ax-float-error .ax-error-message:before{-webkit-margin-start:-1px;margin-inline-start:-1px;border-width:4px;border-bottom-color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message:after{border-width:4px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
21
42
|
}
|
22
43
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormFieldComponent, decorators: [{
|
23
44
|
type: Component,
|
24
|
-
args: [{ selector: 'ax-form-field', template: `<ng-content></ng-content>`, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, styles: [".ax-dark ax-form.ax-form-normal .ax-error-message{border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-200));color:rgba(var(--ax-color-danger-fore-tint))}.ax-dark ax-form.ax-form-normal .ax-error-message:before,.ax-dark ax-form.ax-form-normal .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form.ax-form-normal .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form form.ax-float-error .ax-error-message{border-color:rgba(var(--ax-color-danger-700));background-color:rgba(var(--ax-color-danger-700));color:rgba(var(--ax-color-danger-fore))}.ax-dark ax-form form.ax-float-error .ax-error-message:before,.ax-dark ax-form form.ax-float-error .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-700))}.ax-dark ax-form form.ax-float-error .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-700))}ax-form-field{position:relative;display:block;width:100%}ax-form-field .ax-error-message{margin-top:.25rem;margin-bottom:.25rem;display:block;font-size:.75rem;line-height:1rem}ax-form{width:100%}ax-form form.ax-bottom-error .ax-error-message{color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message{position:absolute;bottom:-2.5rem;z-index:10;display:block;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;border-radius:.375rem;border-width:1px;border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-500));padding:.25rem .5rem;font-weight:400;color:rgba(var(--ax-color-danger-fore))}ax-form form.ax-float-error .ax-error-message:before,ax-form form.ax-float-error .ax-error-message:after{pointer-events:none;position:absolute;bottom:100%;inset-inline-start:.75rem;z-index:20;height:0px;width:0px;border-bottom-color:rgba(var(--ax-color-danger-500));border-inline-end-color:transparent;border-inline-start-color:transparent;border-top-color:transparent;content:\"\"}ax-form form.ax-float-error .ax-error-message:before{-webkit-margin-start:-1px;margin-inline-start:-1px;border-width:4px;border-bottom-color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message:after{border-width:4px}\n"] }]
|
25
|
-
}]
|
45
|
+
args: [{ selector: 'ax-form-field', template: `<ng-content></ng-content>`, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [AXUnsubscriber], styles: [".ax-dark ax-form.ax-form-normal .ax-error-message{border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-200));color:rgba(var(--ax-color-danger-fore-tint))}.ax-dark ax-form.ax-form-normal .ax-error-message:before,.ax-dark ax-form.ax-form-normal .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form.ax-form-normal .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-500))}.ax-dark ax-form form.ax-float-error .ax-error-message{border-color:rgba(var(--ax-color-danger-700));background-color:rgba(var(--ax-color-danger-700));color:rgba(var(--ax-color-danger-fore))}.ax-dark ax-form form.ax-float-error .ax-error-message:before,.ax-dark ax-form form.ax-float-error .ax-error-message:after{border-bottom-color:rgba(var(--ax-color-danger-700))}.ax-dark ax-form form.ax-float-error .ax-error-message:before{border-bottom-color:rgba(var(--ax-color-danger-700))}ax-form-field{position:relative;display:block;width:100%}ax-form-field .ax-error-message{margin-top:.25rem;margin-bottom:.25rem;display:block;font-size:.75rem;line-height:1rem}ax-form{width:100%}ax-form form.ax-bottom-error .ax-error-message{color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message{position:absolute;bottom:-2.5rem;z-index:10;display:block;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;border-radius:.375rem;border-width:1px;border-color:rgba(var(--ax-color-danger-500));background-color:rgba(var(--ax-color-danger-500));padding:.25rem .5rem;font-weight:400;color:rgba(var(--ax-color-danger-fore))}ax-form form.ax-float-error .ax-error-message:before,ax-form form.ax-float-error .ax-error-message:after{pointer-events:none;position:absolute;bottom:100%;inset-inline-start:.75rem;z-index:20;height:0px;width:0px;border-bottom-color:rgba(var(--ax-color-danger-500));border-inline-end-color:transparent;border-inline-start-color:transparent;border-top-color:transparent;content:\"\"}ax-form form.ax-float-error .ax-error-message:before{-webkit-margin-start:-1px;margin-inline-start:-1px;border-width:4px;border-bottom-color:rgba(var(--ax-color-danger-500))}ax-form form.ax-float-error .ax-error-message:after{border-width:4px}\n"] }]
|
46
|
+
}], propDecorators: { input: [{
|
47
|
+
type: ContentChild,
|
48
|
+
args: [AXValuableComponent]
|
49
|
+
}], label: [{
|
50
|
+
type: ContentChild,
|
51
|
+
args: [AXLabelComponent]
|
52
|
+
}] } });
|
26
53
|
|
27
54
|
/**
|
28
55
|
* Contains native event
|
@@ -31,7 +58,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
31
58
|
class AXFormValidationEvent extends AXEvent {
|
32
59
|
}
|
33
60
|
/**
|
34
|
-
* The
|
61
|
+
* The AXForm is a component which detects user interaction and triggers a corresponding event
|
35
62
|
*
|
36
63
|
* @category Components
|
37
64
|
*/
|
@@ -42,7 +69,6 @@ class AXFormComponent extends MXBaseComponent {
|
|
42
69
|
this.onValidate = new EventEmitter();
|
43
70
|
this.updateOnChange = new EventEmitter();
|
44
71
|
this._updateOn = 'blur';
|
45
|
-
this.validateInitValues = false;
|
46
72
|
this._subs = [];
|
47
73
|
}
|
48
74
|
get updateOn() {
|
@@ -53,92 +79,55 @@ class AXFormComponent extends MXBaseComponent {
|
|
53
79
|
name: 'updateOn',
|
54
80
|
value: v,
|
55
81
|
afterCallback: () => {
|
56
|
-
this._bindEvents();
|
82
|
+
//this._bindEvents();
|
57
83
|
},
|
58
84
|
});
|
59
85
|
}
|
60
|
-
_handleSubmit(e) {
|
86
|
+
async _handleSubmit(e) {
|
61
87
|
e.preventDefault();
|
62
|
-
this.validate();
|
88
|
+
await this.validate();
|
63
89
|
}
|
64
90
|
_handleReset() {
|
65
91
|
this.clear();
|
66
92
|
}
|
67
|
-
_getComponenets() {
|
68
|
-
return Array.from(this.getHostElement().querySelectorAll('[ax-form-input="true"]'))
|
69
|
-
.map((c) => c.__axContext__)
|
70
|
-
.filter((c) => c != null);
|
71
|
-
}
|
72
93
|
ngAfterViewInit() {
|
73
|
-
|
74
|
-
this._validateInitValues();
|
75
|
-
}
|
76
|
-
this._bindEvents();
|
77
|
-
// const config = { attributes: false, childList: true, subtree: true };
|
78
|
-
// const callback = (mutationList, observer) => {
|
79
|
-
// this._bindEvents();
|
80
|
-
// };
|
81
|
-
// // Create an observer instance linked to the callback function
|
82
|
-
// if (typeof MutationObserver !== 'undefined') {
|
83
|
-
// this._observer = new MutationObserver(callback);
|
84
|
-
// }
|
85
|
-
// this._observer.observe(this.getHostElement(), config);
|
86
|
-
}
|
87
|
-
_bindEvents() {
|
88
|
-
this._clearSubs();
|
89
|
-
const widgets = this._getComponenets();
|
90
|
-
//
|
91
|
-
widgets.forEach((w) => {
|
92
|
-
if (this.updateOn == 'change') {
|
93
|
-
this._subs.push(w.onValueChanged?.subscribe((v) => {
|
94
|
-
if (v.isUserInteraction)
|
95
|
-
w.validate();
|
96
|
-
}));
|
97
|
-
}
|
98
|
-
else if (this.updateOn == 'blur') {
|
99
|
-
this._subs.push(w.onBlur?.subscribe((v) => {
|
100
|
-
w.validate();
|
101
|
-
}));
|
102
|
-
}
|
103
|
-
});
|
94
|
+
//this._bindEvents();
|
104
95
|
}
|
96
|
+
// private _bindEvents() {
|
97
|
+
// this._clearSubs();
|
98
|
+
// const widgets = this._getComponenets();
|
99
|
+
// //
|
100
|
+
// widgets.forEach((w) => {
|
101
|
+
// if (this.updateOn == 'change') {
|
102
|
+
// this._subs.push(
|
103
|
+
// w.onValueChanged?.subscribe((v: AXValueChangedEvent) => {
|
104
|
+
// if (v.isUserInteraction) w.validate();
|
105
|
+
// }),
|
106
|
+
// );
|
107
|
+
// } else if (this.updateOn == 'blur') {
|
108
|
+
// this._subs.push(
|
109
|
+
// w.onBlur?.subscribe((v) => {
|
110
|
+
// w.validate();
|
111
|
+
// }),
|
112
|
+
// );
|
113
|
+
// }
|
114
|
+
// });
|
115
|
+
// }
|
105
116
|
_clearSubs() {
|
106
117
|
this._subs.forEach((c) => c?.unsubscribe());
|
107
118
|
this._subs = [];
|
108
119
|
}
|
109
|
-
|
110
|
-
this.
|
111
|
-
.filter((c) => c
|
112
|
-
.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
//
|
121
|
-
return new Promise((resolve) => {
|
122
|
-
Promise.all(widgets
|
123
|
-
.filter((c) => args == null || args.length == 0 || args.includes(c.name))
|
124
|
-
.map((c) => c.validate())).then((rules) => {
|
125
|
-
const failed = rules.filter((c) => !c.result);
|
126
|
-
if (failed.length) {
|
127
|
-
this._emitOnValidateEvent({
|
128
|
-
result: false,
|
129
|
-
items: failed,
|
130
|
-
});
|
131
|
-
resolve({
|
132
|
-
result: false,
|
133
|
-
items: failed,
|
134
|
-
});
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
this._emitOnValidateEvent({ result: true });
|
138
|
-
resolve({ result: true });
|
139
|
-
}
|
140
|
-
});
|
141
|
-
});
|
120
|
+
async validate(...names) {
|
121
|
+
const results = await Promise.all(this.fields
|
122
|
+
.filter((c) => names == null || names.length == 0 || names.includes(c.name))
|
123
|
+
.map(field => field.validate()));
|
124
|
+
// Merge all validation summaries into one
|
125
|
+
const mergedSummary = {
|
126
|
+
result: results.every(res => res.result),
|
127
|
+
rules: results.flatMap(res => res.rules)
|
128
|
+
};
|
129
|
+
this._emitOnValidateEvent(mergedSummary);
|
130
|
+
return mergedSummary;
|
142
131
|
}
|
143
132
|
_emitOnValidateEvent(e) {
|
144
133
|
this.onValidate.emit({
|
@@ -148,18 +137,13 @@ class AXFormComponent extends MXBaseComponent {
|
|
148
137
|
});
|
149
138
|
}
|
150
139
|
clear() {
|
151
|
-
|
152
|
-
widgets.forEach((w) => {
|
153
|
-
if (typeof w?.clear === 'function')
|
154
|
-
w.clear(false);
|
155
|
-
});
|
140
|
+
this.fields.forEach(c => c.clear(false));
|
156
141
|
}
|
157
142
|
ngOnDestroy() {
|
158
|
-
this._observer?.disconnect();
|
159
143
|
this._clearSubs();
|
160
144
|
}
|
161
145
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
162
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXFormComponent, selector: "ax-form", inputs: { messageStyle: "messageStyle", updateOn: "updateOn"
|
146
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXFormComponent, selector: "ax-form", inputs: { messageStyle: "messageStyle", updateOn: "updateOn" }, outputs: { onValidate: "onValidate", updateOnChange: "updateOnChange" }, queries: [{ propertyName: "fields", predicate: AXValuableComponent, descendants: true }], usesInheritance: true, ngImport: i0, template: `<form
|
163
147
|
(submit)="_handleSubmit($event)"
|
164
148
|
(reset)="_handleReset()"
|
165
149
|
class="ax-{{ messageStyle }}-error"
|
@@ -189,34 +173,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
189
173
|
type: Output
|
190
174
|
}], updateOn: [{
|
191
175
|
type: Input
|
192
|
-
}],
|
193
|
-
type:
|
176
|
+
}], fields: [{
|
177
|
+
type: ContentChildren,
|
178
|
+
args: [AXValuableComponent, { descendants: true }]
|
194
179
|
}] } });
|
195
180
|
|
196
181
|
const AX_FORM_CONFIG = new InjectionToken('AX_FORM_CONFIG', {
|
197
182
|
providedIn: 'root',
|
198
183
|
factory: () => {
|
199
|
-
const global = inject(AX_GLOBAL_CONFIG);
|
200
|
-
set(global, 'form', AX_FORM_CONFIG);
|
201
184
|
return AXFormDefaultConfig;
|
202
185
|
},
|
203
186
|
});
|
204
|
-
const AXFormDefaultConfig = {
|
205
|
-
validation: {
|
206
|
-
rules: {
|
207
|
-
email: {
|
208
|
-
rule: 'regex',
|
209
|
-
value: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
210
|
-
message: AXTranslator.get('validation.messages.email'),
|
211
|
-
},
|
212
|
-
phone: {
|
213
|
-
rule: 'regex',
|
214
|
-
value: /^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/,
|
215
|
-
message: AXTranslator.get('validation.messages.phone'),
|
216
|
-
},
|
217
|
-
},
|
218
|
-
},
|
219
|
-
};
|
187
|
+
const AXFormDefaultConfig = {};
|
220
188
|
function formConfig(config = {}) {
|
221
189
|
const result = {
|
222
190
|
...AXFormDefaultConfig,
|
@@ -225,124 +193,6 @@ function formConfig(config = {}) {
|
|
225
193
|
return result;
|
226
194
|
}
|
227
195
|
|
228
|
-
class AXValidationRuleComponent extends MXBaseComponent {
|
229
|
-
ngOnInit() {
|
230
|
-
super.ngOnInit();
|
231
|
-
this.getHostElement().validate = this.validate.bind(this);
|
232
|
-
}
|
233
|
-
/**
|
234
|
-
* @ignore
|
235
|
-
*/
|
236
|
-
constructor(control) {
|
237
|
-
super();
|
238
|
-
this.control = control;
|
239
|
-
this._config = inject(AX_FORM_CONFIG);
|
240
|
-
this.rule = 'required';
|
241
|
-
this.showMessage = true;
|
242
|
-
this.enabled = true;
|
243
|
-
}
|
244
|
-
validate(value) {
|
245
|
-
if (this.enabled === false) {
|
246
|
-
return Promise.resolve({ result: true });
|
247
|
-
}
|
248
|
-
if (this.rule == 'custom') {
|
249
|
-
const regRule = this._config.validation.rules[this.value];
|
250
|
-
if (regRule) {
|
251
|
-
return this._internalValidate(regRule.rule, value, this.message || regRule.message, regRule.value);
|
252
|
-
}
|
253
|
-
}
|
254
|
-
return this._internalValidate(this.rule, value, this.message, this.value);
|
255
|
-
}
|
256
|
-
_internalValidate(type, value, message, ruleValue) {
|
257
|
-
return new Promise((resolve) => {
|
258
|
-
switch (type) {
|
259
|
-
case 'required':
|
260
|
-
resolve({
|
261
|
-
message: this.showMessage
|
262
|
-
? message || AXTranslator.get('validation.messages.required', { name: this.control?.name })
|
263
|
-
: '',
|
264
|
-
result: !this._isNullOrEmpty(value),
|
265
|
-
});
|
266
|
-
break;
|
267
|
-
case 'regex':
|
268
|
-
const ex = new RegExp(ruleValue);
|
269
|
-
resolve({
|
270
|
-
message: this.showMessage ? message || AXTranslator.get('validation.messages.regex') : '',
|
271
|
-
result: ex.test(value),
|
272
|
-
});
|
273
|
-
break;
|
274
|
-
case 'callback':
|
275
|
-
if (typeof ruleValue === 'function') {
|
276
|
-
const res = {};
|
277
|
-
res.message = this.showMessage ? message : null;
|
278
|
-
const val = ruleValue({ value, message });
|
279
|
-
if (val instanceof Promise) {
|
280
|
-
val
|
281
|
-
.then((c) => {
|
282
|
-
res.result = c;
|
283
|
-
})
|
284
|
-
.catch((c) => {
|
285
|
-
res.result = false;
|
286
|
-
})
|
287
|
-
.finally(() => {
|
288
|
-
resolve(res);
|
289
|
-
});
|
290
|
-
}
|
291
|
-
else {
|
292
|
-
res.result = val;
|
293
|
-
resolve(res);
|
294
|
-
}
|
295
|
-
}
|
296
|
-
else {
|
297
|
-
resolve({
|
298
|
-
message: AXTranslator.get('validation.messages.invalid-rull-fn'),
|
299
|
-
result: false,
|
300
|
-
});
|
301
|
-
}
|
302
|
-
break;
|
303
|
-
default:
|
304
|
-
resolve({
|
305
|
-
message: AXTranslator.get('validation.messages.invalid-rull-name'),
|
306
|
-
result: false,
|
307
|
-
});
|
308
|
-
}
|
309
|
-
});
|
310
|
-
}
|
311
|
-
_isNullOrEmpty(value) {
|
312
|
-
return (value === undefined ||
|
313
|
-
value === null ||
|
314
|
-
Number.isNaN(value) ||
|
315
|
-
(Array.isArray(value) && value.length == 0) ||
|
316
|
-
(typeof value === 'string' && value.trim().length === 0));
|
317
|
-
}
|
318
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRuleComponent, deps: [{ token: AXValuableComponent, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
319
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXValidationRuleComponent, selector: "ax-validation-rule", inputs: { rule: "rule", message: "message", showMessage: "showMessage", value: "value", enabled: "enabled" }, usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
320
|
-
}
|
321
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRuleComponent, decorators: [{
|
322
|
-
type: Component,
|
323
|
-
args: [{
|
324
|
-
selector: 'ax-validation-rule',
|
325
|
-
template: '',
|
326
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
327
|
-
encapsulation: ViewEncapsulation.None,
|
328
|
-
}]
|
329
|
-
}], ctorParameters: () => [{ type: i1.AXValuableComponent, decorators: [{
|
330
|
-
type: Optional
|
331
|
-
}, {
|
332
|
-
type: Inject,
|
333
|
-
args: [AXValuableComponent]
|
334
|
-
}] }], propDecorators: { rule: [{
|
335
|
-
type: Input
|
336
|
-
}], message: [{
|
337
|
-
type: Input
|
338
|
-
}], showMessage: [{
|
339
|
-
type: Input
|
340
|
-
}], value: [{
|
341
|
-
type: Input
|
342
|
-
}], enabled: [{
|
343
|
-
type: Input
|
344
|
-
}] } });
|
345
|
-
|
346
196
|
class AXValidationSummaryComponent extends MXBaseComponent {
|
347
197
|
get title() {
|
348
198
|
return this._title;
|
@@ -350,25 +200,28 @@ class AXValidationSummaryComponent extends MXBaseComponent {
|
|
350
200
|
set title(v) {
|
351
201
|
this._title = v;
|
352
202
|
}
|
353
|
-
constructor(_tosatService,
|
203
|
+
constructor(_tosatService, host) {
|
354
204
|
super();
|
355
205
|
this._tosatService = _tosatService;
|
356
|
-
this.
|
357
|
-
this._content =
|
206
|
+
this.host = host;
|
207
|
+
this._content = null;
|
358
208
|
this._title = AXTranslator.get('validation.messages.title');
|
359
209
|
this.displayMode = 'toast';
|
360
210
|
this.autoHide = false;
|
361
211
|
//
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
212
|
+
this.sub = host.onValidate
|
213
|
+
.subscribe((e) => {
|
214
|
+
if (!e.result.result) {
|
215
|
+
const failedRules = e.result.rules.filter(c => !c.result && c.message);
|
216
|
+
this._content = `<ul>${failedRules.map((c) => `<li>${c.message}</li>`).join('')}</ul>`;
|
217
|
+
this._timeOut = this.autoHide ? (this.timeOut ?? Math.max(failedRules.length * 1000, 2000)) : 0;
|
366
218
|
//
|
367
219
|
if (this.displayMode == 'toast') {
|
368
220
|
this._tosatService.show({
|
369
221
|
color: 'danger',
|
370
222
|
closeButton: true,
|
371
223
|
timeOut: this._timeOut,
|
224
|
+
timeOutProgress: true,
|
372
225
|
content: this._content,
|
373
226
|
title: this.title,
|
374
227
|
location: 'bottom-center',
|
@@ -376,22 +229,25 @@ class AXValidationSummaryComponent extends MXBaseComponent {
|
|
376
229
|
}
|
377
230
|
}
|
378
231
|
else {
|
379
|
-
this._content =
|
232
|
+
this._content = null;
|
380
233
|
}
|
381
234
|
this.cdr.markForCheck();
|
382
235
|
});
|
383
236
|
}
|
384
|
-
_handleOnDismissed(
|
385
|
-
this._content =
|
237
|
+
_handleOnDismissed() {
|
238
|
+
this._content = null;
|
239
|
+
}
|
240
|
+
ngOnDestroy() {
|
241
|
+
this.sub?.unsubscribe();
|
386
242
|
}
|
387
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationSummaryComponent, deps: [{ token: i1
|
243
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationSummaryComponent, deps: [{ token: i1.AXToastService }, { token: AXFormComponent, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
388
244
|
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.8", type: AXValidationSummaryComponent, selector: "ax-validation-summary", inputs: { title: "title", displayMode: "displayMode", timeOut: "timeOut", autoHide: "autoHide" }, usesInheritance: true, ngImport: i0, template: `
|
389
245
|
<ax-alert
|
390
246
|
color="danger"
|
391
247
|
*ngIf="displayMode === 'alert' && _content"
|
392
248
|
[timeOut]="_timeOut"
|
393
249
|
#a
|
394
|
-
(onClosed)="_handleOnDismissed(
|
250
|
+
(onClosed)="_handleOnDismissed()"
|
395
251
|
>
|
396
252
|
<ax-icon></ax-icon>
|
397
253
|
<ax-title>{{ title }}</ax-title>
|
@@ -416,7 +272,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
416
272
|
*ngIf="displayMode === 'alert' && _content"
|
417
273
|
[timeOut]="_timeOut"
|
418
274
|
#a
|
419
|
-
(onClosed)="_handleOnDismissed(
|
275
|
+
(onClosed)="_handleOnDismissed()"
|
420
276
|
>
|
421
277
|
<ax-icon></ax-icon>
|
422
278
|
<ax-title>{{ title }}</ax-title>
|
@@ -433,7 +289,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
433
289
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
434
290
|
encapsulation: ViewEncapsulation.None,
|
435
291
|
}]
|
436
|
-
}], ctorParameters: () => [{ type: i1
|
292
|
+
}], ctorParameters: () => [{ type: i1.AXToastService }, { type: AXFormComponent, decorators: [{
|
437
293
|
type: Optional
|
438
294
|
}, {
|
439
295
|
type: Inject,
|
@@ -448,13 +304,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
448
304
|
type: Input
|
449
305
|
}] } });
|
450
306
|
|
307
|
+
class AXValidationRuleDirective {
|
308
|
+
constructor(host) {
|
309
|
+
this.host = host;
|
310
|
+
}
|
311
|
+
ngOnInit() {
|
312
|
+
this.host.addValidationRule({ rule: this.rule, options: this.ruleOptions });
|
313
|
+
}
|
314
|
+
ngOnDestroy() {
|
315
|
+
this.host.removeValidationRule({ rule: this.rule, options: this.ruleOptions });
|
316
|
+
}
|
317
|
+
get ruleOptions() {
|
318
|
+
return Object.assign({ message: this.message, name: this.host.name }, this.options);
|
319
|
+
}
|
320
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRuleDirective, deps: [{ token: i1$1.AXValuableComponent }], target: i0.ɵɵFactoryTarget.Directive }); }
|
321
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.0.8", type: AXValidationRuleDirective, selector: "ax-validation-rule", inputs: { rule: "rule", options: "options", message: "message" }, ngImport: i0 }); }
|
322
|
+
}
|
323
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRuleDirective, decorators: [{
|
324
|
+
type: Directive,
|
325
|
+
args: [{
|
326
|
+
selector: 'ax-validation-rule'
|
327
|
+
}]
|
328
|
+
}], ctorParameters: () => [{ type: i1$1.AXValuableComponent }], propDecorators: { rule: [{
|
329
|
+
type: Input
|
330
|
+
}], options: [{
|
331
|
+
type: Input
|
332
|
+
}], message: [{
|
333
|
+
type: Input
|
334
|
+
}] } });
|
335
|
+
|
451
336
|
class AXFormModule {
|
452
337
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
453
338
|
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXFormModule, declarations: [AXFormFieldComponent,
|
454
339
|
AXFormComponent,
|
455
|
-
|
456
|
-
AXValidationSummaryComponent], imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule], exports: [AXFormFieldComponent, AXFormComponent,
|
457
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormModule, imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule] }); }
|
340
|
+
AXValidationRuleDirective,
|
341
|
+
AXValidationSummaryComponent], imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule, AXValidationModule], exports: [AXFormFieldComponent, AXFormComponent, AXValidationRuleDirective, AXValidationSummaryComponent] }); }
|
342
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormModule, imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule, AXValidationModule] }); }
|
458
343
|
}
|
459
344
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormModule, decorators: [{
|
460
345
|
type: NgModule,
|
@@ -462,11 +347,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
462
347
|
declarations: [
|
463
348
|
AXFormFieldComponent,
|
464
349
|
AXFormComponent,
|
465
|
-
|
350
|
+
AXValidationRuleDirective,
|
466
351
|
AXValidationSummaryComponent,
|
467
352
|
],
|
468
|
-
imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule],
|
469
|
-
exports: [AXFormFieldComponent, AXFormComponent,
|
353
|
+
imports: [CommonModule, AXDecoratorModule, AXAlertModule, AXButtonModule, AXValidationModule],
|
354
|
+
exports: [AXFormFieldComponent, AXFormComponent, AXValidationRuleDirective, AXValidationSummaryComponent],
|
470
355
|
providers: [],
|
471
356
|
}]
|
472
357
|
}] });
|
@@ -475,5 +360,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
475
360
|
* Generated bundle index. Do not edit.
|
476
361
|
*/
|
477
362
|
|
478
|
-
export { AXFormComponent, AXFormDefaultConfig, AXFormFieldComponent, AXFormModule, AXFormValidationEvent,
|
363
|
+
export { AXFormComponent, AXFormDefaultConfig, AXFormFieldComponent, AXFormModule, AXFormValidationEvent, AXValidationRuleDirective, AXValidationSummaryComponent, AX_FORM_CONFIG, formConfig };
|
479
364
|
//# sourceMappingURL=acorex-components-form.mjs.map
|