@bcweed/dynamic-form-lib 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -15
- package/fesm2022/bcweed-dynamic-form-lib.mjs +948 -0
- package/fesm2022/bcweed-dynamic-form-lib.mjs.map +1 -0
- package/index.d.ts +257 -0
- package/package.json +37 -65
- package/.editorconfig +0 -17
- package/.postcssrc.json +0 -5
- package/.vscode/extensions.json +0 -4
- package/.vscode/launch.json +0 -20
- package/.vscode/tasks.json +0 -42
- package/AngularDynamicFormLibrary.esproj +0 -14
- package/CHANGELOG.md +0 -16
- package/angular.json +0 -169
- package/aspnetcore-https.js +0 -37
- package/karma.conf.js +0 -44
- package/obj/Debug/AngularDynamicFormLibrary.esproj.CoreCompileInputs.cache +0 -0
- package/obj/Debug/AngularDynamicFormLibrary.esproj.FileListAbsolute.txt +0 -1
- package/obj/Debug/package.g.props +0 -56
- package/postcss.config.js +0 -6
- package/projects/dynamic-form-lib/.postcssrc.json +0 -5
- package/projects/dynamic-form-lib/README.md +0 -63
- package/projects/dynamic-form-lib/ng-package.json +0 -10
- package/projects/dynamic-form-lib/package.json +0 -27
- package/projects/dynamic-form-lib/src/lib/README.md +0 -424
- package/projects/dynamic-form-lib/src/lib/SUMMARY.md +0 -159
- package/projects/dynamic-form-lib/src/lib/directives/dynamic-ref-directive.ts +0 -13
- package/projects/dynamic-form-lib/src/lib/dynamic-form-demo/dynamic-form-demo.component.html +0 -75
- package/projects/dynamic-form-lib/src/lib/dynamic-form-demo/dynamic-form-demo.component.scss +0 -127
- package/projects/dynamic-form-lib/src/lib/dynamic-form-demo/dynamic-form-demo.component.ts +0 -50
- package/projects/dynamic-form-lib/src/lib/dynamic-form-field/dynamic-form-field.component.html +0 -234
- package/projects/dynamic-form-lib/src/lib/dynamic-form-field/dynamic-form-field.component.scss +0 -315
- package/projects/dynamic-form-lib/src/lib/dynamic-form-field/dynamic-form-field.component.ts +0 -233
- package/projects/dynamic-form-lib/src/lib/dynamic-form.component.html +0 -137
- package/projects/dynamic-form-lib/src/lib/dynamic-form.component.scss +0 -141
- package/projects/dynamic-form-lib/src/lib/dynamic-form.component.ts +0 -366
- package/projects/dynamic-form-lib/src/lib/helpers/component-helper.ts +0 -54
- package/projects/dynamic-form-lib/src/lib/index.ts +0 -10
- package/projects/dynamic-form-lib/src/lib/models/dynamic-form-interfaces.ts +0 -117
- package/projects/dynamic-form-lib/src/lib/services/dynamic-form.service.spec.ts +0 -302
- package/projects/dynamic-form-lib/src/lib/services/dynamic-form.service.ts +0 -325
- package/projects/dynamic-form-lib/src/lib/style.scss +0 -3
- package/projects/dynamic-form-lib/src/lib/tailwind-output.css +0 -0
- package/projects/dynamic-form-lib/src/lib/validators/compare-validator.ts +0 -26
- package/projects/dynamic-form-lib/src/public-api.css +0 -1
- package/projects/dynamic-form-lib/src/public-api.ts +0 -10
- package/projects/dynamic-form-lib/tailwind.config.js +0 -10
- package/projects/dynamic-form-lib/tsconfig.lib.json +0 -15
- package/projects/dynamic-form-lib/tsconfig.lib.prod.json +0 -11
- package/projects/dynamic-form-lib/tsconfig.spec.json +0 -15
- package/public/favicon.ico +0 -0
- package/src/app/app-routing.module.ts +0 -10
- package/src/app/app.component.css +0 -0
- package/src/app/app.component.html +0 -18
- package/src/app/app.component.spec.ts +0 -35
- package/src/app/app.component.ts +0 -1038
- package/src/app/app.config.ts +0 -45
- package/src/app/app.module.ts +0 -46
- package/src/app/app.routes.ts +0 -8
- package/src/index.html +0 -13
- package/src/main.ts +0 -16
- package/src/styles.css +0 -2
- package/tailwind.config.js +0 -10
- package/tsconfig.app.json +0 -15
- package/tsconfig.json +0 -32
- package/tsconfig.spec.json +0 -15
- /package/{projects/dynamic-form-lib/src → src}/lib/style.css +0 -0
|
@@ -0,0 +1,948 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Input, Directive, ViewChild, Component, Injectable, inject, EventEmitter, ViewChildren, Output } from '@angular/core';
|
|
3
|
+
import * as i2 from '@angular/common';
|
|
4
|
+
import { CommonModule } from '@angular/common';
|
|
5
|
+
import * as i3 from '@angular/forms';
|
|
6
|
+
import { ReactiveFormsModule, Validators, FormBuilder } from '@angular/forms';
|
|
7
|
+
import { Subject } from 'rxjs';
|
|
8
|
+
import { takeUntil } from 'rxjs/operators';
|
|
9
|
+
import * as i4 from 'primeng/inputtext';
|
|
10
|
+
import { InputTextModule } from 'primeng/inputtext';
|
|
11
|
+
import * as i5 from 'primeng/textarea';
|
|
12
|
+
import { TextareaModule } from 'primeng/textarea';
|
|
13
|
+
import * as i6 from 'primeng/inputnumber';
|
|
14
|
+
import { InputNumberModule } from 'primeng/inputnumber';
|
|
15
|
+
import * as i7 from 'primeng/checkbox';
|
|
16
|
+
import { CheckboxModule } from 'primeng/checkbox';
|
|
17
|
+
import * as i8 from 'primeng/radiobutton';
|
|
18
|
+
import { RadioButtonModule, RadioButton } from 'primeng/radiobutton';
|
|
19
|
+
import * as i9 from 'primeng/select';
|
|
20
|
+
import { SelectModule } from 'primeng/select';
|
|
21
|
+
import * as i10 from 'primeng/datepicker';
|
|
22
|
+
import { DatePickerModule } from 'primeng/datepicker';
|
|
23
|
+
import * as i11 from 'primeng/message';
|
|
24
|
+
import { MessageModule } from 'primeng/message';
|
|
25
|
+
import * as i12 from 'primeng/tooltip';
|
|
26
|
+
import { TooltipModule } from 'primeng/tooltip';
|
|
27
|
+
import * as i13 from 'primeng/scrollpanel';
|
|
28
|
+
import { ScrollPanelModule } from 'primeng/scrollpanel';
|
|
29
|
+
import * as i14 from 'primeng/popover';
|
|
30
|
+
import { PopoverModule } from 'primeng/popover';
|
|
31
|
+
import * as i15 from 'primeng/drawer';
|
|
32
|
+
import { DrawerModule } from 'primeng/drawer';
|
|
33
|
+
import * as i16 from 'primeng/inputmask';
|
|
34
|
+
import { InputMaskModule } from 'primeng/inputmask';
|
|
35
|
+
import * as i1 from '@angular/cdk/layout';
|
|
36
|
+
import { Breakpoints } from '@angular/cdk/layout';
|
|
37
|
+
import * as i4$1 from 'primeng/button';
|
|
38
|
+
import { ButtonModule } from 'primeng/button';
|
|
39
|
+
|
|
40
|
+
class DynamicRefDirective {
|
|
41
|
+
el;
|
|
42
|
+
refKey;
|
|
43
|
+
constructor(el) {
|
|
44
|
+
this.el = el;
|
|
45
|
+
const t = this.refKey;
|
|
46
|
+
}
|
|
47
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicRefDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
48
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.18", type: DynamicRefDirective, isStandalone: true, selector: "[dynamicRef]", inputs: { refKey: "refKey" }, ngImport: i0 });
|
|
49
|
+
}
|
|
50
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicRefDirective, decorators: [{
|
|
51
|
+
type: Directive,
|
|
52
|
+
args: [{
|
|
53
|
+
selector: '[dynamicRef]',
|
|
54
|
+
standalone: true
|
|
55
|
+
}]
|
|
56
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { refKey: [{
|
|
57
|
+
type: Input
|
|
58
|
+
}] } });
|
|
59
|
+
|
|
60
|
+
class DynamicFormFieldComponent {
|
|
61
|
+
responsive;
|
|
62
|
+
field;
|
|
63
|
+
form;
|
|
64
|
+
errors = [];
|
|
65
|
+
allowHelpOverlay = false;
|
|
66
|
+
allowHelpSideBar = false;
|
|
67
|
+
ref;
|
|
68
|
+
elementRef = null;
|
|
69
|
+
radioButton;
|
|
70
|
+
helpSideBarVisible = false;
|
|
71
|
+
shouldDisable = true;
|
|
72
|
+
isExpanded = false;
|
|
73
|
+
isSmallMedia = false;
|
|
74
|
+
isMediumMedia = false;
|
|
75
|
+
constructor(responsive) {
|
|
76
|
+
this.responsive = responsive;
|
|
77
|
+
}
|
|
78
|
+
ngOnInit() {
|
|
79
|
+
this.responsive.observe([Breakpoints.Medium, Breakpoints.Small, Breakpoints.XSmall])
|
|
80
|
+
.subscribe(result => {
|
|
81
|
+
if (result.matches) {
|
|
82
|
+
this.isSmallMedia = true;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.isSmallMedia = false;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (!this.field || !this.form) {
|
|
89
|
+
console.error('DynamicFormFieldComponent requires field and form inputs');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
ngAfterViewInit() {
|
|
93
|
+
if (this.radioButton) {
|
|
94
|
+
this.elementRef = this.radioButton.inputViewChild;
|
|
95
|
+
}
|
|
96
|
+
if (this.ref) {
|
|
97
|
+
this.elementRef = this.ref.el;
|
|
98
|
+
}
|
|
99
|
+
if ((this.field.conditionalDisabled && this.field.conditionalDisabled()) || this.field.disabled) {
|
|
100
|
+
this.form.controls[this.field.id].disable();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
get isValid() {
|
|
104
|
+
const control = this.form.get(this.field.id);
|
|
105
|
+
return control ? control.valid : true;
|
|
106
|
+
}
|
|
107
|
+
get isTouched() {
|
|
108
|
+
const control = this.form.get(this.field.id);
|
|
109
|
+
return control ? control.touched : false;
|
|
110
|
+
}
|
|
111
|
+
get isDirty() {
|
|
112
|
+
const control = this.form.get(this.field.id);
|
|
113
|
+
return control ? control.dirty : false;
|
|
114
|
+
}
|
|
115
|
+
get showError() {
|
|
116
|
+
return !this.isValid && (this.isTouched || this.isDirty);
|
|
117
|
+
}
|
|
118
|
+
get fieldClasses() {
|
|
119
|
+
const classes = ['form-group'];
|
|
120
|
+
if (this.showError) {
|
|
121
|
+
if (!this.field.disabled) {
|
|
122
|
+
classes.push('field-error');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (this.isValid && (this.isTouched || this.isDirty)) {
|
|
126
|
+
classes.push('field-valid');
|
|
127
|
+
}
|
|
128
|
+
if (this.field.disabled) {
|
|
129
|
+
classes.push('field-disabled');
|
|
130
|
+
}
|
|
131
|
+
if (this.field.required) {
|
|
132
|
+
classes.push('field-required');
|
|
133
|
+
}
|
|
134
|
+
return classes.join(' ');
|
|
135
|
+
}
|
|
136
|
+
get successIndicatorClass() {
|
|
137
|
+
if (this.field.type == 'select') {
|
|
138
|
+
return "valid-indicator-select";
|
|
139
|
+
}
|
|
140
|
+
else if (this.field.type == 'date') {
|
|
141
|
+
return "valid-indicator-calendar";
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return "valid-indicator";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
get controlName() {
|
|
148
|
+
return this.field.id;
|
|
149
|
+
}
|
|
150
|
+
focusOn() {
|
|
151
|
+
if (this.elementRef) {
|
|
152
|
+
this.elementRef.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
153
|
+
this.elementRef.nativeElement.focus();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
onBlur() {
|
|
157
|
+
const control = this.form.get(this.field.id);
|
|
158
|
+
if (control) {
|
|
159
|
+
control.markAsTouched();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
displayRadioError(option) {
|
|
163
|
+
if (option.displayError && typeof option.displayError === 'function') {
|
|
164
|
+
return option.displayError();
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
onClick(event) {
|
|
169
|
+
if (typeof this.field.onClick === 'function') {
|
|
170
|
+
this.field.onClick(event.target.value, this.form);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
onChange(event) {
|
|
174
|
+
if (typeof this.field.onChange === 'function') {
|
|
175
|
+
this.field.onChange(event.target.value, this.form);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
onCheckboxChange(event) {
|
|
179
|
+
if (typeof this.field.onChange === 'function') {
|
|
180
|
+
this.field.onChange((event.checked ? true : false), this.form);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
labelWidthStyle() {
|
|
184
|
+
return this.isSmallMedia ? '100%' : this.field.labelWidth ? this.field.labelWidth : '100%';
|
|
185
|
+
}
|
|
186
|
+
fieldWidthStyle() {
|
|
187
|
+
return this.isSmallMedia ? '100%' : this.field.fieldWidth ? this.field.fieldWidth : '100%';
|
|
188
|
+
}
|
|
189
|
+
inputWidthStyle() {
|
|
190
|
+
return this.isSmallMedia ? '100%' : this.field.inputWidth ? this.field.inputWidth : '100%';
|
|
191
|
+
}
|
|
192
|
+
trackByFn(index, item) {
|
|
193
|
+
return item.value;
|
|
194
|
+
}
|
|
195
|
+
get getMinValue() {
|
|
196
|
+
if (this.field.type === 'number' && this.field.min !== undefined) {
|
|
197
|
+
return this.field.min;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
get getMaxValue() {
|
|
202
|
+
if (this.field.type === 'number' && this.field.max !== undefined) {
|
|
203
|
+
return this.field.max;
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
get getDecimalPlace() {
|
|
208
|
+
if (this.field.type === 'number' && this.field.decimals !== undefined) {
|
|
209
|
+
return this.field.decimals;
|
|
210
|
+
}
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
isFieldDisabled() {
|
|
214
|
+
const t = (this.field.conditionalDisabled && this.field.conditionalDisabled()) ? '' : null;
|
|
215
|
+
return t;
|
|
216
|
+
}
|
|
217
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormFieldComponent, deps: [{ token: i1.BreakpointObserver }], target: i0.ɵɵFactoryTarget.Component });
|
|
218
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.18", type: DynamicFormFieldComponent, isStandalone: true, selector: "app-dynamic-form-field", inputs: { field: "field", form: "form", errors: "errors", allowHelpOverlay: "allowHelpOverlay", allowHelpSideBar: "allowHelpSideBar" }, viewQueries: [{ propertyName: "ref", first: true, predicate: DynamicRefDirective, descendants: true }, { propertyName: "radioButton", first: true, predicate: RadioButton, descendants: true }], ngImport: i0, template: "\r\n<div [ngClass]=\"fieldClasses\" [formGroup]=\"form\">\r\n <div [ngStyle]=\"{ width: fieldWidthStyle(), position: 'relative' }\">\r\n <!-- Label -->\r\n <div *ngIf=\"field.leftPreInput\" class=\"left-pre-input\">\r\n <span [innerHTML]=\"field.leftPreInput\" class=\"left-pre-input-text\">\r\n </span>\r\n\r\n </div>\r\n <div #field_container class=\"input-container\">\r\n <div class=\"label-row\" [ngStyle]=\"{ width: labelWidthStyle() }\">\r\n <label [attr.for]=\"field.id\" class=\"control-label\">\r\n {{ field.label }}\r\n <span *ngIf=\"field.required\" class=\"required-indicator\">*</span>\r\n </label>\r\n <div class=\"help-icons\">\r\n <i (click)=\"helpSideBarVisible = true\" class=\"pi pi-question-circle\" *ngIf=\"allowHelpSideBar && field.popInfo\"></i>\r\n <i (click)=\"popover.toggle($event)\" class=\"pi pi-question-circle\" *ngIf=\"allowHelpOverlay && field.popInfo\"></i>\r\n </div>\r\n </div>\r\n <!-- Text Input -->\r\n <input *ngIf=\"field.type === 'text'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n class=\"form-control\"\r\n type=\"text\"\r\n pInputText\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\" />\r\n <!-- Email Input -->\r\n <input *ngIf=\"field.type === 'email'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n class=\"form-control\"\r\n type=\"email\"\r\n pInputText\r\n pTooltip=\"{{field.toolTip}}\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\" />\r\n <!-- Number Input -->\r\n <p-inputNumber *ngIf=\"field.type === 'number'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [inputId]=\"field.id\"\r\n [useGrouping]=\"false\"\r\n [minFractionDigits]=\"getDecimalPlace\"\r\n [min]=\"getMinValue\"\r\n [max]=\"getMaxValue\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n styleClass=\"form-control\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-inputNumber>\r\n\r\n\r\n <!-- phone -->\r\n\r\n <p-inputMask *ngIf=\"field.type === 'phone'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n mask=\"(999) 999-9999\"\r\n unmask=\"true\"\r\n styleClass=\"form-control-phone\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-inputMask>\r\n <!-- Textarea -->\r\n <textarea *ngIf=\"field.type === 'textarea'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n [rows]=\"5\"\r\n class=\"form-control\"\r\n pInputTextarea\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></textarea>\r\n\r\n <!-- Date Picker -->\r\n <p-datepicker *ngIf=\"field.type === 'date'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [inputId]=\"field.id\"\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n styleClass=\"form-control-datepicker\"\r\n dateFormat=\"DD MM yy\"\r\n [showIcon]=\"true\"\r\n [style]=\"{ width: inputWidthStyle() }\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-datepicker>\r\n\r\n <!-- Select Dropdown -->\r\n <p-select *ngIf=\"field.type === 'select'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [inputId]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [id]=\"field.id\"\r\n appendTo=\"body\"\r\n [options]=\"field.options || []\"\r\n [placeholder]=\"field.placeholder || 'Select an option'\"\r\n optionLabel=\"label\"\r\n optionValue=\"value\"\r\n styleClass=\"form-control-select\"\r\n [showClear]=\"!field.required\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-select>\r\n\r\n <!-- Checkbox -->\r\n <div *ngIf=\"field.type === 'checkbox'\" class=\"checkbox-wrapper\">\r\n <p-checkbox [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [inputId]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [style]=\"{ width: inputWidthStyle() }\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n [binary]=\"true\"\r\n tooltipPosition=\"right\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onChange)=\"onCheckboxChange($event)\"></p-checkbox>\r\n </div>\r\n\r\n <!-- Radio Buttons -->\r\n <div *ngIf=\"field.type === 'radio'\" class=\"radio-group\">\r\n <div *ngFor=\"let option of field.options; trackBy: trackByFn; let first = first\"\r\n class=\"radio-option\" tooltipPosition=\"right\" pTooltip=\"{{option.toolTip}}\">\r\n\r\n <p-radioButton *ngIf=\"first\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [inputId]=\"field.id + '_' + option.value\"\r\n [id]=\"field.id + '_' + option.value\"\r\n [name]=\"field.id\"\r\n [value]=\"option.value\"\r\n [formControlName]=\"controlName\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event.originalEvent)\"></p-radioButton>\r\n <p-radioButton *ngIf=\"!first\"\r\n [inputId]=\"field.id + '_' + option.value\"\r\n [id]=\"field.id + '_' + option.value\"\r\n [name]=\"field.id\"\r\n [value]=\"option.value\"\r\n [formControlName]=\"controlName\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event.originalEvent)\"></p-radioButton>\r\n <label [for]=\"field.id + '_' + option.value\" class=\"radio-label\">\r\n {{ option.label }}\r\n </label>\r\n <div *ngIf=\"option.helpInfo\" class=\"radio-message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"option.helpInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"option.errorInfo && displayRadioError(option)\" class=\"radio-message-container\">\r\n <p-message severity=\"error\">\r\n <div [innerHTML]=\"option.errorInfo\"></div>\r\n </p-message>\r\n </div>\r\n <small class=\"radion-hint\" *ngIf=\"option.hint\" id=\"field.id + '_' + option.value + '-help'\">{{option.hint}}</small>\r\n\r\n\r\n </div>\r\n </div>\r\n <small class=\"field-hint\" *ngIf=\"field.hint\" id=\"field.id + '-help'\">{{field.hint}}</small>\r\n </div>\r\n <!-- Error Messages -->\r\n <div *ngIf=\"showError\" class=\"error-messages\">\r\n <p-message *ngFor=\"let error of errors\"\r\n severity=\"error\"\r\n [text]=\"error\"></p-message>\r\n </div>\r\n\r\n <div *ngIf=\"field.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"field.postInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"field.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"field.postWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <!-- Valid Indicator (optional) -->\r\n <div *ngIf=\"isValid && isTouched && field.required\" [ngClass]=\"successIndicatorClass\">\r\n <i class=\"pi pi-check-circle\"></i>\r\n </div>\r\n </div>\r\n</div>\r\n\r\n<p-popover appendTo=\"body\" styleClass=\"form-pop-info\" #popover>\r\n <h4>{{field.label}}</h4>\r\n <div [innerHTML]=\"field.popInfo\"></div>\r\n</p-popover>\r\n@if (allowHelpSideBar && field.popInfo) {\r\n <p-drawer header=\"{{field.label}}\" autoZIndex=\"false\" baseZIndex=\"10000\" [ngStyle]=\"{'z-index': '10000', 'top': '65px'}\" position=\"right\" styleClass=\"form-pop-info\" appendTo=\"body\" [(visible)]=\"helpSideBarVisible\">\r\n <p-scrollPanel [ngStyle]=\"{height: '100%'}\">\r\n <div [innerHTML]=\"field.popInfo\"></div>\r\n </p-scrollPanel>\r\n </p-drawer>\r\n}\r\n", styles: [".p-overlay-mask,.p-drawer .p-drawer.form-pop-info{z-index:10000!important}.p-drawer-right,.p-drawer.form-pop-info.p-drawer-right{top:65px}p-message .p-message.light-font .p-message-text{font-weight:400}.form-group{margin-bottom:1rem;position:relative;transition:all .3s ease;display:flex;flex-wrap:wrap;gap:.75rem}.form-group .left-pre-input{display:flex;flex-direction:column;justify-content:flex-end;align-items:flex-end;flex-basis:40%;flex-shrink:0;flex-grow:0}.form-group .left-pre-input .left-pre-input-text{text-align:right;width:100%;margin-bottom:10px;font-weight:600}.form-group .input-container{flex-grow:1;flex-shrink:1;min-width:0}.form-group .label-row{display:flex;justify-content:space-between;align-items:start;margin-bottom:.5rem}.form-group .help-icons{display:flex;gap:.5rem;margin-left:.5rem}.form-group .help-icons i{cursor:pointer;color:#6c757d;transition:color .2s ease}.form-group .help-icons i:hover{color:#007bff}.form-group .control-label{display:block;font-weight:500;color:#333}.form-group .control-label .required-indicator{color:#dc3545;margin-left:.25rem}.form-group .form-control{width:100%;transition:border-color .3s ease,box-shadow .3s ease}.form-group .field-hint{display:block;margin-top:.25rem;font-size:.875rem;color:#6c757d}.form-group .checkbox-wrapper{padding:.5rem 0}.form-group .radio-group{display:flex;flex-direction:column;gap:.75rem}.form-group .radio-group .radio-option{display:flex;align-items:center;flex-wrap:wrap}.form-group .radio-group .radio-option .radio-label{margin:0;cursor:pointer;font-weight:400}.form-group .radio-group .radio-option .radion-hint{flex-basis:100%;width:100%;display:block;margin-left:36px;font-size:.875rem;color:#6c757d}.form-group .radio-group .radio-option .radio-message-container{flex-basis:100%;width:100%;margin-top:.25rem;margin-left:36px}.form-group .error-messages{margin-top:.5rem;flex-basis:100%;width:100%;animation:slideDown .3s ease}.form-group .error-messages ::ng-deep .p-message{margin-bottom:.25rem}.form-group .error-messages ::ng-deep .p-message:last-child{margin-bottom:0}.form-group .valid-indicator,.form-group .valid-indicator-select,.form-group .valid-indicator-calendar{position:absolute;color:#28a745;font-size:1.2rem;animation:fadeIn .3s ease}.form-group .valid-indicator i,.form-group .valid-indicator-select i,.form-group .valid-indicator-calendar i{display:block}.form-group .valid-indicator{right:10px;top:38px}.form-group .valid-indicator-select,.form-group .valid-indicator-calendar{right:80px;top:38px}.form-group .p-select,.form-group ::ng-deep .p-datepicker,.form-group .p-inputnumber{padding:0}.form-group .p-datepicker>span>input,.form-group .p-inputnumber{border:none!important}.form-group.field-error .form-control,.form-group.field-error ::ng-deep .p-inputtext,.form-group.field-error ::ng-deep .p-select,.form-group.field-error ::ng-deep .p-datepicker,.form-group.field-error ::ng-deep .p-inputnumber input{border-color:#dc3545!important}.form-group.field-error .form-control:focus,.form-group.field-error ::ng-deep .p-inputtext:focus,.form-group.field-error ::ng-deep .p-select:focus,.form-group.field-error ::ng-deep .p-datepicker:focus,.form-group.field-error ::ng-deep .p-inputnumber input:focus{box-shadow:0 0 0 .2rem #dc354540}.form-group.field-error .p-datepicker>span>input{border:none!important}.form-group.field-error .control-label{color:#dc3545}.form-group.field-valid .form-control,.form-group.field-valid ::ng-deep .p-inputtext,.form-group.field-valid ::ng-deep .p-select,.form-group.field-valid ::ng-deep .p-datepicker,.form-group.field-valid ::ng-deep .p-inputnumber input{border-color:#28a745}.form-group.field-valid .form-control:focus,.form-group.field-valid ::ng-deep .p-inputtext:focus,.form-group.field-valid ::ng-deep .p-select:focus,.form-group.field-valid ::ng-deep .p-datepicker:focus,.form-group.field-valid ::ng-deep .p-inputnumber input:focus{box-shadow:0 0 0 .2rem #28a74540}.form-group.field-valid .p-datepicker>span>input{border:none!important}.form-group.field-disabled{opacity:.6;pointer-events:none}.form-group.field-disabled .control-label{color:#6c757d}.form-group.field-error{padding:12px;border:1px solid #dc3545;background-color:var(--p-red-100);box-shadow:0 0 10px #00000080;border-radius:10px}@keyframes slideDown{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}::ng-deep .p-inputtext,::ng-deep .p-select,::ng-deep .p-datepicker .p-inputtext,::ng-deep .p-inputnumber-input{width:100%}::ng-deep .p-select{display:flex}::ng-deep .p-datepicker{width:100%}::ng-deep .p-datepicker .p-inputtext{width:100%}::ng-deep .p-inputnumber{width:100%}::ng-deep .p-checkbox{margin-right:.5rem}::ng-deep .p-radiobutton{margin-right:.5rem}@media (max-width: 768px){.form-group .radio-group .radio-option{flex-direction:row;align-items:flex-start}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "ngmodule", type: InputTextModule }, { kind: "directive", type: i4.InputText, selector: "[pInputText]", inputs: ["hostName", "ptInputText", "pSize", "variant", "fluid", "invalid"] }, { kind: "ngmodule", type: TextareaModule }, { kind: "directive", type: i5.Textarea, selector: "[pTextarea], [pInputTextarea]", inputs: ["autoResize", "pSize", "variant", "fluid", "invalid"], outputs: ["onResize"] }, { kind: "ngmodule", type:
|
|
219
|
+
//InputTextarea,
|
|
220
|
+
InputNumberModule }, { kind: "component", type: i6.InputNumber, selector: "p-inputNumber, p-inputnumber, p-input-number", inputs: ["showButtons", "format", "buttonLayout", "inputId", "styleClass", "placeholder", "tabindex", "title", "ariaLabelledBy", "ariaDescribedBy", "ariaLabel", "ariaRequired", "autocomplete", "incrementButtonClass", "decrementButtonClass", "incrementButtonIcon", "decrementButtonIcon", "readonly", "allowEmpty", "locale", "localeMatcher", "mode", "currency", "currencyDisplay", "useGrouping", "minFractionDigits", "maxFractionDigits", "prefix", "suffix", "inputStyle", "inputStyleClass", "showClear", "autofocus"], outputs: ["onInput", "onFocus", "onBlur", "onKeyDown", "onClear"] }, { kind: "ngmodule", type: CheckboxModule }, { kind: "component", type: i7.Checkbox, selector: "p-checkbox, p-checkBox, p-check-box", inputs: ["hostName", "value", "binary", "ariaLabelledBy", "ariaLabel", "tabindex", "inputId", "inputStyle", "styleClass", "inputClass", "indeterminate", "formControl", "checkboxIcon", "readonly", "autofocus", "trueValue", "falseValue", "variant", "size"], outputs: ["onChange", "onFocus", "onBlur"] }, { kind: "ngmodule", type: RadioButtonModule }, { kind: "component", type: i8.RadioButton, selector: "p-radioButton, p-radiobutton, p-radio-button", inputs: ["value", "tabindex", "inputId", "ariaLabelledBy", "ariaLabel", "styleClass", "autofocus", "binary", "variant", "size"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "ngmodule", type: SelectModule }, { kind: "component", type: i9.Select, selector: "p-select", inputs: ["id", "scrollHeight", "filter", "panelStyle", "styleClass", "panelStyleClass", "readonly", "editable", "tabindex", "placeholder", "loadingIcon", "filterPlaceholder", "filterLocale", "inputId", "dataKey", "filterBy", "filterFields", "autofocus", "resetFilterOnHide", "checkmark", "dropdownIcon", "loading", "optionLabel", "optionValue", "optionDisabled", "optionGroupLabel", "optionGroupChildren", "group", "showClear", "emptyFilterMessage", "emptyMessage", "lazy", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "overlayOptions", "ariaFilterLabel", "ariaLabel", "ariaLabelledBy", "filterMatchMode", "tooltip", "tooltipPosition", "tooltipPositionStyle", "tooltipStyleClass", "focusOnHover", "selectOnFocus", "autoOptionFocus", "autofocusFilter", "filterValue", "options", "appendTo"], outputs: ["onChange", "onFilter", "onFocus", "onBlur", "onClick", "onShow", "onHide", "onClear", "onLazyLoad"] }, { kind: "ngmodule", type:
|
|
221
|
+
//DropdownModule,
|
|
222
|
+
DatePickerModule }, { kind: "component", type: i10.DatePicker, selector: "p-datePicker, p-datepicker, p-date-picker", inputs: ["iconDisplay", "styleClass", "inputStyle", "inputId", "inputStyleClass", "placeholder", "ariaLabelledBy", "ariaLabel", "iconAriaLabel", "dateFormat", "multipleSeparator", "rangeSeparator", "inline", "showOtherMonths", "selectOtherMonths", "showIcon", "icon", "readonlyInput", "shortYearCutoff", "hourFormat", "timeOnly", "stepHour", "stepMinute", "stepSecond", "showSeconds", "showOnFocus", "showWeek", "startWeekFromFirstDayOfYear", "showClear", "dataType", "selectionMode", "maxDateCount", "showButtonBar", "todayButtonStyleClass", "clearButtonStyleClass", "autofocus", "autoZIndex", "baseZIndex", "panelStyleClass", "panelStyle", "keepInvalid", "hideOnDateTimeSelect", "touchUI", "timeSeparator", "focusTrap", "showTransitionOptions", "hideTransitionOptions", "tabindex", "minDate", "maxDate", "disabledDates", "disabledDays", "showTime", "responsiveOptions", "numberOfMonths", "firstDayOfWeek", "view", "defaultDate", "appendTo"], outputs: ["onFocus", "onBlur", "onClose", "onSelect", "onClear", "onInput", "onTodayClick", "onClearClick", "onMonthChange", "onYearChange", "onClickOutside", "onShow"] }, { kind: "ngmodule", type:
|
|
223
|
+
//CalendarModule,
|
|
224
|
+
MessageModule }, { kind: "component", type: i11.Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant"], outputs: ["onClose"] }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i12.Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "pTooltip", "tooltipDisabled", "tooltipOptions", "appendTo", "ptTooltip"] }, { kind: "directive", type: DynamicRefDirective, selector: "[dynamicRef]", inputs: ["refKey"] }, { kind: "ngmodule", type: ScrollPanelModule }, { kind: "component", type: i13.ScrollPanel, selector: "p-scroll-panel, p-scrollPanel, p-scrollpanel", inputs: ["styleClass", "step"] }, { kind: "ngmodule", type: PopoverModule }, { kind: "component", type: i14.Popover, selector: "p-popover", inputs: ["ariaLabel", "ariaLabelledBy", "dismissable", "style", "styleClass", "appendTo", "autoZIndex", "ariaCloseLabel", "baseZIndex", "focusOnShow", "showTransitionOptions", "hideTransitionOptions"], outputs: ["onShow", "onHide"] }, { kind: "ngmodule", type: DrawerModule }, { kind: "component", type: i15.Drawer, selector: "p-drawer", inputs: ["appendTo", "blockScroll", "style", "styleClass", "ariaCloseLabel", "autoZIndex", "baseZIndex", "modal", "closeButtonProps", "dismissible", "showCloseIcon", "closeOnEscape", "transitionOptions", "visible", "position", "fullScreen", "header", "maskStyle", "closable"], outputs: ["onShow", "onHide", "visibleChange"] }, { kind: "ngmodule", type: InputMaskModule }, { kind: "component", type: i16.InputMask, selector: "p-inputmask, p-inputMask, p-input-mask", inputs: ["type", "slotChar", "autoClear", "showClear", "style", "inputId", "styleClass", "placeholder", "tabindex", "title", "ariaLabel", "ariaLabelledBy", "ariaRequired", "readonly", "unmask", "characterPattern", "autofocus", "autocomplete", "keepBuffer", "mask"], outputs: ["onComplete", "onFocus", "onBlur", "onInput", "onKeydown", "onClear"] }] });
|
|
225
|
+
}
|
|
226
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormFieldComponent, decorators: [{
|
|
227
|
+
type: Component,
|
|
228
|
+
args: [{ selector: 'app-dynamic-form-field', standalone: true, imports: [
|
|
229
|
+
CommonModule,
|
|
230
|
+
ReactiveFormsModule,
|
|
231
|
+
InputTextModule,
|
|
232
|
+
TextareaModule,
|
|
233
|
+
//InputTextarea,
|
|
234
|
+
InputNumberModule,
|
|
235
|
+
CheckboxModule,
|
|
236
|
+
RadioButtonModule,
|
|
237
|
+
SelectModule,
|
|
238
|
+
//DropdownModule,
|
|
239
|
+
DatePickerModule,
|
|
240
|
+
//CalendarModule,
|
|
241
|
+
MessageModule,
|
|
242
|
+
TooltipModule,
|
|
243
|
+
DynamicRefDirective,
|
|
244
|
+
ScrollPanelModule,
|
|
245
|
+
PopoverModule,
|
|
246
|
+
DrawerModule,
|
|
247
|
+
InputMaskModule
|
|
248
|
+
], template: "\r\n<div [ngClass]=\"fieldClasses\" [formGroup]=\"form\">\r\n <div [ngStyle]=\"{ width: fieldWidthStyle(), position: 'relative' }\">\r\n <!-- Label -->\r\n <div *ngIf=\"field.leftPreInput\" class=\"left-pre-input\">\r\n <span [innerHTML]=\"field.leftPreInput\" class=\"left-pre-input-text\">\r\n </span>\r\n\r\n </div>\r\n <div #field_container class=\"input-container\">\r\n <div class=\"label-row\" [ngStyle]=\"{ width: labelWidthStyle() }\">\r\n <label [attr.for]=\"field.id\" class=\"control-label\">\r\n {{ field.label }}\r\n <span *ngIf=\"field.required\" class=\"required-indicator\">*</span>\r\n </label>\r\n <div class=\"help-icons\">\r\n <i (click)=\"helpSideBarVisible = true\" class=\"pi pi-question-circle\" *ngIf=\"allowHelpSideBar && field.popInfo\"></i>\r\n <i (click)=\"popover.toggle($event)\" class=\"pi pi-question-circle\" *ngIf=\"allowHelpOverlay && field.popInfo\"></i>\r\n </div>\r\n </div>\r\n <!-- Text Input -->\r\n <input *ngIf=\"field.type === 'text'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n class=\"form-control\"\r\n type=\"text\"\r\n pInputText\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\" />\r\n <!-- Email Input -->\r\n <input *ngIf=\"field.type === 'email'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n class=\"form-control\"\r\n type=\"email\"\r\n pInputText\r\n pTooltip=\"{{field.toolTip}}\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\" />\r\n <!-- Number Input -->\r\n <p-inputNumber *ngIf=\"field.type === 'number'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [inputId]=\"field.id\"\r\n [useGrouping]=\"false\"\r\n [minFractionDigits]=\"getDecimalPlace\"\r\n [min]=\"getMinValue\"\r\n [max]=\"getMaxValue\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n styleClass=\"form-control\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-inputNumber>\r\n\r\n\r\n <!-- phone -->\r\n\r\n <p-inputMask *ngIf=\"field.type === 'phone'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n mask=\"(999) 999-9999\"\r\n unmask=\"true\"\r\n styleClass=\"form-control-phone\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-inputMask>\r\n <!-- Textarea -->\r\n <textarea *ngIf=\"field.type === 'textarea'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n [rows]=\"5\"\r\n class=\"form-control\"\r\n pInputTextarea\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (blur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></textarea>\r\n\r\n <!-- Date Picker -->\r\n <p-datepicker *ngIf=\"field.type === 'date'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [inputId]=\"field.id\"\r\n [id]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [placeholder]=\"field.placeholder || ''\"\r\n styleClass=\"form-control-datepicker\"\r\n dateFormat=\"DD MM yy\"\r\n [showIcon]=\"true\"\r\n [style]=\"{ width: inputWidthStyle() }\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-datepicker>\r\n\r\n <!-- Select Dropdown -->\r\n <p-select *ngIf=\"field.type === 'select'\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [inputId]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [id]=\"field.id\"\r\n appendTo=\"body\"\r\n [options]=\"field.options || []\"\r\n [placeholder]=\"field.placeholder || 'Select an option'\"\r\n optionLabel=\"label\"\r\n optionValue=\"value\"\r\n styleClass=\"form-control-select\"\r\n [showClear]=\"!field.required\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n tooltipPosition=\"bottom\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event)\"></p-select>\r\n\r\n <!-- Checkbox -->\r\n <div *ngIf=\"field.type === 'checkbox'\" class=\"checkbox-wrapper\">\r\n <p-checkbox [attr.data-dynamic-id]=\"field.id\"\r\n [refKey]=\"field.id\" dynamicRef\r\n [id]=\"field.id\"\r\n [inputId]=\"field.id\"\r\n [formControlName]=\"controlName\"\r\n [style]=\"{ width: inputWidthStyle() }\"\r\n [ngStyle]=\"{ width: inputWidthStyle() }\"\r\n [binary]=\"true\"\r\n tooltipPosition=\"right\"\r\n pTooltip=\"{{field.toolTip}}\"\r\n (onBlur)=\"onBlur()\"\r\n (onChange)=\"onCheckboxChange($event)\"></p-checkbox>\r\n </div>\r\n\r\n <!-- Radio Buttons -->\r\n <div *ngIf=\"field.type === 'radio'\" class=\"radio-group\">\r\n <div *ngFor=\"let option of field.options; trackBy: trackByFn; let first = first\"\r\n class=\"radio-option\" tooltipPosition=\"right\" pTooltip=\"{{option.toolTip}}\">\r\n\r\n <p-radioButton *ngIf=\"first\"\r\n [attr.data-dynamic-id]=\"field.id\"\r\n [inputId]=\"field.id + '_' + option.value\"\r\n [id]=\"field.id + '_' + option.value\"\r\n [name]=\"field.id\"\r\n [value]=\"option.value\"\r\n [formControlName]=\"controlName\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event.originalEvent)\"></p-radioButton>\r\n <p-radioButton *ngIf=\"!first\"\r\n [inputId]=\"field.id + '_' + option.value\"\r\n [id]=\"field.id + '_' + option.value\"\r\n [name]=\"field.id\"\r\n [value]=\"option.value\"\r\n [formControlName]=\"controlName\"\r\n (onBlur)=\"onBlur()\"\r\n (onClick)=\"onClick($event.originalEvent)\"></p-radioButton>\r\n <label [for]=\"field.id + '_' + option.value\" class=\"radio-label\">\r\n {{ option.label }}\r\n </label>\r\n <div *ngIf=\"option.helpInfo\" class=\"radio-message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"option.helpInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"option.errorInfo && displayRadioError(option)\" class=\"radio-message-container\">\r\n <p-message severity=\"error\">\r\n <div [innerHTML]=\"option.errorInfo\"></div>\r\n </p-message>\r\n </div>\r\n <small class=\"radion-hint\" *ngIf=\"option.hint\" id=\"field.id + '_' + option.value + '-help'\">{{option.hint}}</small>\r\n\r\n\r\n </div>\r\n </div>\r\n <small class=\"field-hint\" *ngIf=\"field.hint\" id=\"field.id + '-help'\">{{field.hint}}</small>\r\n </div>\r\n <!-- Error Messages -->\r\n <div *ngIf=\"showError\" class=\"error-messages\">\r\n <p-message *ngFor=\"let error of errors\"\r\n severity=\"error\"\r\n [text]=\"error\"></p-message>\r\n </div>\r\n\r\n <div *ngIf=\"field.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"field.postInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"field.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"field.postWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <!-- Valid Indicator (optional) -->\r\n <div *ngIf=\"isValid && isTouched && field.required\" [ngClass]=\"successIndicatorClass\">\r\n <i class=\"pi pi-check-circle\"></i>\r\n </div>\r\n </div>\r\n</div>\r\n\r\n<p-popover appendTo=\"body\" styleClass=\"form-pop-info\" #popover>\r\n <h4>{{field.label}}</h4>\r\n <div [innerHTML]=\"field.popInfo\"></div>\r\n</p-popover>\r\n@if (allowHelpSideBar && field.popInfo) {\r\n <p-drawer header=\"{{field.label}}\" autoZIndex=\"false\" baseZIndex=\"10000\" [ngStyle]=\"{'z-index': '10000', 'top': '65px'}\" position=\"right\" styleClass=\"form-pop-info\" appendTo=\"body\" [(visible)]=\"helpSideBarVisible\">\r\n <p-scrollPanel [ngStyle]=\"{height: '100%'}\">\r\n <div [innerHTML]=\"field.popInfo\"></div>\r\n </p-scrollPanel>\r\n </p-drawer>\r\n}\r\n", styles: [".p-overlay-mask,.p-drawer .p-drawer.form-pop-info{z-index:10000!important}.p-drawer-right,.p-drawer.form-pop-info.p-drawer-right{top:65px}p-message .p-message.light-font .p-message-text{font-weight:400}.form-group{margin-bottom:1rem;position:relative;transition:all .3s ease;display:flex;flex-wrap:wrap;gap:.75rem}.form-group .left-pre-input{display:flex;flex-direction:column;justify-content:flex-end;align-items:flex-end;flex-basis:40%;flex-shrink:0;flex-grow:0}.form-group .left-pre-input .left-pre-input-text{text-align:right;width:100%;margin-bottom:10px;font-weight:600}.form-group .input-container{flex-grow:1;flex-shrink:1;min-width:0}.form-group .label-row{display:flex;justify-content:space-between;align-items:start;margin-bottom:.5rem}.form-group .help-icons{display:flex;gap:.5rem;margin-left:.5rem}.form-group .help-icons i{cursor:pointer;color:#6c757d;transition:color .2s ease}.form-group .help-icons i:hover{color:#007bff}.form-group .control-label{display:block;font-weight:500;color:#333}.form-group .control-label .required-indicator{color:#dc3545;margin-left:.25rem}.form-group .form-control{width:100%;transition:border-color .3s ease,box-shadow .3s ease}.form-group .field-hint{display:block;margin-top:.25rem;font-size:.875rem;color:#6c757d}.form-group .checkbox-wrapper{padding:.5rem 0}.form-group .radio-group{display:flex;flex-direction:column;gap:.75rem}.form-group .radio-group .radio-option{display:flex;align-items:center;flex-wrap:wrap}.form-group .radio-group .radio-option .radio-label{margin:0;cursor:pointer;font-weight:400}.form-group .radio-group .radio-option .radion-hint{flex-basis:100%;width:100%;display:block;margin-left:36px;font-size:.875rem;color:#6c757d}.form-group .radio-group .radio-option .radio-message-container{flex-basis:100%;width:100%;margin-top:.25rem;margin-left:36px}.form-group .error-messages{margin-top:.5rem;flex-basis:100%;width:100%;animation:slideDown .3s ease}.form-group .error-messages ::ng-deep .p-message{margin-bottom:.25rem}.form-group .error-messages ::ng-deep .p-message:last-child{margin-bottom:0}.form-group .valid-indicator,.form-group .valid-indicator-select,.form-group .valid-indicator-calendar{position:absolute;color:#28a745;font-size:1.2rem;animation:fadeIn .3s ease}.form-group .valid-indicator i,.form-group .valid-indicator-select i,.form-group .valid-indicator-calendar i{display:block}.form-group .valid-indicator{right:10px;top:38px}.form-group .valid-indicator-select,.form-group .valid-indicator-calendar{right:80px;top:38px}.form-group .p-select,.form-group ::ng-deep .p-datepicker,.form-group .p-inputnumber{padding:0}.form-group .p-datepicker>span>input,.form-group .p-inputnumber{border:none!important}.form-group.field-error .form-control,.form-group.field-error ::ng-deep .p-inputtext,.form-group.field-error ::ng-deep .p-select,.form-group.field-error ::ng-deep .p-datepicker,.form-group.field-error ::ng-deep .p-inputnumber input{border-color:#dc3545!important}.form-group.field-error .form-control:focus,.form-group.field-error ::ng-deep .p-inputtext:focus,.form-group.field-error ::ng-deep .p-select:focus,.form-group.field-error ::ng-deep .p-datepicker:focus,.form-group.field-error ::ng-deep .p-inputnumber input:focus{box-shadow:0 0 0 .2rem #dc354540}.form-group.field-error .p-datepicker>span>input{border:none!important}.form-group.field-error .control-label{color:#dc3545}.form-group.field-valid .form-control,.form-group.field-valid ::ng-deep .p-inputtext,.form-group.field-valid ::ng-deep .p-select,.form-group.field-valid ::ng-deep .p-datepicker,.form-group.field-valid ::ng-deep .p-inputnumber input{border-color:#28a745}.form-group.field-valid .form-control:focus,.form-group.field-valid ::ng-deep .p-inputtext:focus,.form-group.field-valid ::ng-deep .p-select:focus,.form-group.field-valid ::ng-deep .p-datepicker:focus,.form-group.field-valid ::ng-deep .p-inputnumber input:focus{box-shadow:0 0 0 .2rem #28a74540}.form-group.field-valid .p-datepicker>span>input{border:none!important}.form-group.field-disabled{opacity:.6;pointer-events:none}.form-group.field-disabled .control-label{color:#6c757d}.form-group.field-error{padding:12px;border:1px solid #dc3545;background-color:var(--p-red-100);box-shadow:0 0 10px #00000080;border-radius:10px}@keyframes slideDown{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}::ng-deep .p-inputtext,::ng-deep .p-select,::ng-deep .p-datepicker .p-inputtext,::ng-deep .p-inputnumber-input{width:100%}::ng-deep .p-select{display:flex}::ng-deep .p-datepicker{width:100%}::ng-deep .p-datepicker .p-inputtext{width:100%}::ng-deep .p-inputnumber{width:100%}::ng-deep .p-checkbox{margin-right:.5rem}::ng-deep .p-radiobutton{margin-right:.5rem}@media (max-width: 768px){.form-group .radio-group .radio-option{flex-direction:row;align-items:flex-start}}\n"] }]
|
|
249
|
+
}], ctorParameters: () => [{ type: i1.BreakpointObserver }], propDecorators: { field: [{
|
|
250
|
+
type: Input
|
|
251
|
+
}], form: [{
|
|
252
|
+
type: Input
|
|
253
|
+
}], errors: [{
|
|
254
|
+
type: Input
|
|
255
|
+
}], allowHelpOverlay: [{
|
|
256
|
+
type: Input
|
|
257
|
+
}], allowHelpSideBar: [{
|
|
258
|
+
type: Input
|
|
259
|
+
}], ref: [{
|
|
260
|
+
type: ViewChild,
|
|
261
|
+
args: [DynamicRefDirective]
|
|
262
|
+
}], radioButton: [{
|
|
263
|
+
type: ViewChild,
|
|
264
|
+
args: [RadioButton]
|
|
265
|
+
}] } });
|
|
266
|
+
|
|
267
|
+
function compareValidator(matchingControlName) {
|
|
268
|
+
return (control) => {
|
|
269
|
+
const group = control.parent;
|
|
270
|
+
if (!group) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const matchingControl = group.get(matchingControlName);
|
|
274
|
+
if (!matchingControl) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
// Return error on the current control instead of modifying the other
|
|
278
|
+
if (control.value !== matchingControl.value) {
|
|
279
|
+
return { compare: true };
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
class DynamicFormService {
|
|
286
|
+
constructor() { }
|
|
287
|
+
/**
|
|
288
|
+
* Gets the validators for a specific field based on its validations
|
|
289
|
+
*/
|
|
290
|
+
getValidators(fieldOrValidations) {
|
|
291
|
+
let validations = [];
|
|
292
|
+
if (!Array.isArray(fieldOrValidations)) {
|
|
293
|
+
if (!fieldOrValidations.validations || fieldOrValidations.validations.length === 0) {
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
validations = fieldOrValidations.validations;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
validations = fieldOrValidations;
|
|
300
|
+
}
|
|
301
|
+
const validators = [];
|
|
302
|
+
validations.forEach(validation => {
|
|
303
|
+
const validator = this.createValidator(validation);
|
|
304
|
+
if (validator) {
|
|
305
|
+
validators.push(validator);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return validators;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Creates a validator function based on validation type
|
|
312
|
+
*/
|
|
313
|
+
createValidator(validation) {
|
|
314
|
+
switch (validation.type) {
|
|
315
|
+
case 'required':
|
|
316
|
+
return Validators.required;
|
|
317
|
+
case 'minLength':
|
|
318
|
+
return validation.value ? Validators.minLength(validation.value) : null;
|
|
319
|
+
case 'maxLength':
|
|
320
|
+
return validation.value ? Validators.maxLength(validation.value) : null;
|
|
321
|
+
case 'min':
|
|
322
|
+
return validation.value !== undefined ? Validators.min(validation.value) : null;
|
|
323
|
+
case 'max':
|
|
324
|
+
return validation.value !== undefined ? Validators.max(validation.value) : null;
|
|
325
|
+
case 'compare':
|
|
326
|
+
return validation.compareToField !== undefined ? compareValidator(validation.compareToField) : null;
|
|
327
|
+
case 'email':
|
|
328
|
+
return Validators.email;
|
|
329
|
+
case 'pattern':
|
|
330
|
+
return validation.value ? Validators.pattern(validation.value) : null;
|
|
331
|
+
case 'custom':
|
|
332
|
+
return validation.validator ? this.customValidator(validation) : null;
|
|
333
|
+
default:
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Creates a custom validator wrapper
|
|
339
|
+
*/
|
|
340
|
+
customValidator(validation) {
|
|
341
|
+
return (control) => {
|
|
342
|
+
if (!validation.validator) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
const isValid = validation.validator(control.value);
|
|
346
|
+
return isValid ? null : { custom: { message: validation.message } };
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Gets error messages for a field based on its validation errors
|
|
351
|
+
*/
|
|
352
|
+
getErrorMessages(field, errors) {
|
|
353
|
+
if (!errors || !field.validations) {
|
|
354
|
+
return [];
|
|
355
|
+
}
|
|
356
|
+
const errorMessages = [];
|
|
357
|
+
field.validations.forEach(validation => {
|
|
358
|
+
const errorKey = this.getErrorKey(validation.type);
|
|
359
|
+
if (errors[errorKey]) {
|
|
360
|
+
errorMessages.push({
|
|
361
|
+
fieldId: field.id,
|
|
362
|
+
message: validation.message
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
return errorMessages;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Maps validation type to Angular error key
|
|
370
|
+
*/
|
|
371
|
+
getErrorKey(validationType) {
|
|
372
|
+
switch (validationType) {
|
|
373
|
+
case 'required':
|
|
374
|
+
return 'required';
|
|
375
|
+
case 'minLength':
|
|
376
|
+
return 'minlength';
|
|
377
|
+
case 'maxLength':
|
|
378
|
+
return 'maxlength';
|
|
379
|
+
case 'min':
|
|
380
|
+
return 'min';
|
|
381
|
+
case 'max':
|
|
382
|
+
return 'max';
|
|
383
|
+
case 'email':
|
|
384
|
+
return 'email';
|
|
385
|
+
case 'pattern':
|
|
386
|
+
return 'pattern';
|
|
387
|
+
case 'custom':
|
|
388
|
+
return 'custom';
|
|
389
|
+
case 'compare':
|
|
390
|
+
return 'compare';
|
|
391
|
+
default:
|
|
392
|
+
return validationType;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Validates a complete form configuration
|
|
397
|
+
*/
|
|
398
|
+
validateFormConfig(config) {
|
|
399
|
+
if (!config || !config.id || !config.frames) {
|
|
400
|
+
console.error('Invalid form config: missing required properties');
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
if (!Array.isArray(config.frames) || config.frames.length === 0) {
|
|
404
|
+
console.error('Invalid form config: frames must be a non-empty array');
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
for (const frame of config.frames) {
|
|
408
|
+
if (!Array.isArray(frame.sections) || frame.sections.length === 0) {
|
|
409
|
+
console.error('Invalid form config: sections must be a non-empty array');
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (!Array.isArray(config.frames[0].sections) || config.frames[0].sections.length === 0 || !Array.isArray(config.frames[0].sections[0].fields) || config.frames[0].sections[0].fields.length === 0) {
|
|
414
|
+
console.error('Invalid form config: fields must be a non-empty array');
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
for (const frame of config.frames) {
|
|
418
|
+
for (const section of frame.sections) {
|
|
419
|
+
for (const field of section.fields) {
|
|
420
|
+
if (!field.id || !field.label || !field.type) {
|
|
421
|
+
console.error('Invalid field config: missing required properties', field);
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
const validTypes = ['text', 'number', 'email', 'select', 'checkbox', 'radio', 'date', 'textarea'];
|
|
425
|
+
if (!validTypes.includes(field.type)) {
|
|
426
|
+
console.error(`Invalid field type: ${field.type}`, field);
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
if ((field.type === 'select' || field.type === 'radio') && (!field.options || field.options.length === 0)) {
|
|
430
|
+
console.error(`Field type ${field.type} requires options`, field);
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Creates a sample form configuration for testing
|
|
440
|
+
*/
|
|
441
|
+
createSampleConfig() {
|
|
442
|
+
return {
|
|
443
|
+
id: 'sample-form',
|
|
444
|
+
title: 'Sample Dynamic Form',
|
|
445
|
+
description: 'This is a sample form configuration demonstrating all field types.',
|
|
446
|
+
sections: [
|
|
447
|
+
{
|
|
448
|
+
id: 'sample-form',
|
|
449
|
+
title: 'Sample Dynamic Form',
|
|
450
|
+
description: 'This is a sample form configuration demonstrating all field types.',
|
|
451
|
+
fields: [
|
|
452
|
+
{
|
|
453
|
+
id: 'firstName',
|
|
454
|
+
label: 'First Name',
|
|
455
|
+
type: 'text',
|
|
456
|
+
placeholder: 'Enter your first name',
|
|
457
|
+
required: true,
|
|
458
|
+
order: 1,
|
|
459
|
+
validations: [
|
|
460
|
+
{
|
|
461
|
+
type: 'required',
|
|
462
|
+
message: 'First name is required'
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
type: 'minLength',
|
|
466
|
+
value: 2,
|
|
467
|
+
message: 'First name must be at least 2 characters'
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
id: 'email',
|
|
473
|
+
label: 'Email Address',
|
|
474
|
+
type: 'email',
|
|
475
|
+
placeholder: 'Enter your email',
|
|
476
|
+
required: true,
|
|
477
|
+
order: 2,
|
|
478
|
+
validations: [
|
|
479
|
+
{
|
|
480
|
+
type: 'required',
|
|
481
|
+
message: 'Email is required'
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
type: 'email',
|
|
485
|
+
message: 'Please enter a valid email address'
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
id: 'age',
|
|
491
|
+
label: 'Age',
|
|
492
|
+
type: 'number',
|
|
493
|
+
placeholder: 'Enter your age',
|
|
494
|
+
order: 3,
|
|
495
|
+
validations: [
|
|
496
|
+
{
|
|
497
|
+
type: 'min',
|
|
498
|
+
value: 18,
|
|
499
|
+
message: 'You must be at least 18 years old'
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
type: 'max',
|
|
503
|
+
value: 120,
|
|
504
|
+
message: 'Age must be less than 120'
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
id: 'country',
|
|
510
|
+
label: 'Country',
|
|
511
|
+
type: 'select',
|
|
512
|
+
placeholder: 'Select your country',
|
|
513
|
+
required: true,
|
|
514
|
+
order: 4,
|
|
515
|
+
options: [
|
|
516
|
+
{ label: 'United States', value: 'US' },
|
|
517
|
+
{ label: 'Canada', value: 'CA' },
|
|
518
|
+
{ label: 'United Kingdom', value: 'UK' },
|
|
519
|
+
{ label: 'Australia', value: 'AU' }
|
|
520
|
+
],
|
|
521
|
+
validations: [
|
|
522
|
+
{
|
|
523
|
+
type: 'required',
|
|
524
|
+
message: 'Country is required'
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
id: 'gender',
|
|
530
|
+
label: 'Gender',
|
|
531
|
+
type: 'radio',
|
|
532
|
+
order: 5,
|
|
533
|
+
options: [
|
|
534
|
+
{ label: 'Male', value: 'male' },
|
|
535
|
+
{ label: 'Female', value: 'female' },
|
|
536
|
+
{ label: 'Other', value: 'other' }
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
id: 'newsletter',
|
|
541
|
+
label: 'Subscribe to newsletter',
|
|
542
|
+
type: 'checkbox',
|
|
543
|
+
order: 6,
|
|
544
|
+
value: false
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
id: 'birthDate',
|
|
548
|
+
label: 'Birth Date',
|
|
549
|
+
type: 'date',
|
|
550
|
+
placeholder: 'Select your birth date',
|
|
551
|
+
order: 7
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
id: 'comments',
|
|
555
|
+
label: 'Comments',
|
|
556
|
+
type: 'textarea',
|
|
557
|
+
placeholder: 'Enter any additional comments',
|
|
558
|
+
order: 8,
|
|
559
|
+
validations: [
|
|
560
|
+
{
|
|
561
|
+
type: 'maxLength',
|
|
562
|
+
value: 500,
|
|
563
|
+
message: 'Comments must be less than 500 characters'
|
|
564
|
+
}
|
|
565
|
+
]
|
|
566
|
+
}
|
|
567
|
+
],
|
|
568
|
+
}
|
|
569
|
+
],
|
|
570
|
+
submitLabel: 'Submit Form',
|
|
571
|
+
cancelLabel: 'Cancel'
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
575
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormService, providedIn: 'root' });
|
|
576
|
+
}
|
|
577
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormService, decorators: [{
|
|
578
|
+
type: Injectable,
|
|
579
|
+
args: [{
|
|
580
|
+
providedIn: 'root'
|
|
581
|
+
}]
|
|
582
|
+
}], ctorParameters: () => [] });
|
|
583
|
+
|
|
584
|
+
class DynamicFormComponent {
|
|
585
|
+
responsive;
|
|
586
|
+
// Inject dependencies using field initializers (this IS the injection context)
|
|
587
|
+
fb = inject(FormBuilder);
|
|
588
|
+
dynamicFormService = inject(DynamicFormService);
|
|
589
|
+
config;
|
|
590
|
+
initialValues;
|
|
591
|
+
allowHelpOverlay = false;
|
|
592
|
+
allowHelpSideBar = false;
|
|
593
|
+
formSubmit = new EventEmitter();
|
|
594
|
+
formCancel = new EventEmitter();
|
|
595
|
+
formStateChange = new EventEmitter();
|
|
596
|
+
fieldComponents;
|
|
597
|
+
componentMap;
|
|
598
|
+
fieldMap;
|
|
599
|
+
form;
|
|
600
|
+
formState;
|
|
601
|
+
sortedFields = [];
|
|
602
|
+
sortedSections = [];
|
|
603
|
+
sortedFrames = [];
|
|
604
|
+
destroy$ = new Subject();
|
|
605
|
+
isExpanded = false;
|
|
606
|
+
isSmallMedia = false;
|
|
607
|
+
isMediumMedia = false;
|
|
608
|
+
// Empty constructor - no code needed here
|
|
609
|
+
constructor(responsive) {
|
|
610
|
+
this.responsive = responsive;
|
|
611
|
+
}
|
|
612
|
+
ngOnInit() {
|
|
613
|
+
this.responsive.observe([Breakpoints.Medium, Breakpoints.Small, Breakpoints.XSmall])
|
|
614
|
+
.subscribe(result => {
|
|
615
|
+
if (result.matches) {
|
|
616
|
+
this.isSmallMedia = true;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
this.isSmallMedia = false;
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
this.initializeForm();
|
|
623
|
+
this.subscribeToFormChanges();
|
|
624
|
+
}
|
|
625
|
+
ngOnDestroy() {
|
|
626
|
+
this.destroy$.next();
|
|
627
|
+
this.destroy$.complete();
|
|
628
|
+
}
|
|
629
|
+
ngAfterViewInit() {
|
|
630
|
+
this.componentMap = new Map(this.fieldComponents.map(comp => [comp.field.id, comp]));
|
|
631
|
+
}
|
|
632
|
+
initializeForm() {
|
|
633
|
+
//sort frames
|
|
634
|
+
// Sort sections and fields by order
|
|
635
|
+
this.sortedFrames = [...this.config.frames].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
636
|
+
this.sortedFrames.forEach((frame) => {
|
|
637
|
+
frame.sections = [...frame.sections].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
638
|
+
frame.sections.forEach((section) => {
|
|
639
|
+
section.fields = [...section.fields].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
// Build field map for O(1) lookup
|
|
643
|
+
this.fieldMap = new Map();
|
|
644
|
+
this.sortedFrames.forEach(frame => {
|
|
645
|
+
frame.sections.forEach(section => {
|
|
646
|
+
section.fields.forEach(field => {
|
|
647
|
+
this.fieldMap.set(field.id, field);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
// Build form controls
|
|
652
|
+
const group = {};
|
|
653
|
+
this.sortedFrames.forEach(frame => {
|
|
654
|
+
frame.sections.forEach(section => {
|
|
655
|
+
section.fields.forEach(field => {
|
|
656
|
+
const validators = field.disabled === true ? [] : this.dynamicFormService.getValidators(field);
|
|
657
|
+
const initialValue = this.getInitialValue(field);
|
|
658
|
+
group[field.id] = [
|
|
659
|
+
{ value: initialValue, disabled: field.disabled ?? false },
|
|
660
|
+
validators
|
|
661
|
+
];
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
this.form = this.fb.group(group);
|
|
666
|
+
// Trigger all click events on form controls
|
|
667
|
+
this.triggerAllClickEvents();
|
|
668
|
+
// Initialize form state
|
|
669
|
+
this.formState = {
|
|
670
|
+
values: this.form.value,
|
|
671
|
+
errors: [],
|
|
672
|
+
touched: {},
|
|
673
|
+
isSubmitting: false,
|
|
674
|
+
isValid: this.form.valid
|
|
675
|
+
};
|
|
676
|
+
if (this.form.valid) {
|
|
677
|
+
this.markAllAsTouched();
|
|
678
|
+
}
|
|
679
|
+
this.emitFormState();
|
|
680
|
+
}
|
|
681
|
+
triggerAllClickEvents() {
|
|
682
|
+
this.sortedFrames.forEach(frame => {
|
|
683
|
+
frame.sections.forEach(section => {
|
|
684
|
+
section.fields.forEach(field => {
|
|
685
|
+
const control = this.form.get(field.id);
|
|
686
|
+
if (control && field.onClick) {
|
|
687
|
+
// Trigger the onClick event with current control value
|
|
688
|
+
field.onClick(control.value, this.form);
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
getInitialValue(field) {
|
|
695
|
+
if (this.initialValues && this.initialValues[field.id] !== undefined) {
|
|
696
|
+
//return this.initialValues[field.id];
|
|
697
|
+
if (field.type == "date") {
|
|
698
|
+
if (this.initialValues[field.id] instanceof Date && !isNaN(this.initialValues[field.id].getTime())) {
|
|
699
|
+
console.log(field.id + " is already a valid Date object");
|
|
700
|
+
return this.initialValues[field.id];
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
console.log(field.id + " is not a valid Date object, attempting to parse");
|
|
704
|
+
return new Date(this.initialValues[field.id]);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
return this.initialValues[field.id];
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return field.value ?? this.getDefaultValue(field.type);
|
|
712
|
+
}
|
|
713
|
+
getDefaultValue(type) {
|
|
714
|
+
switch (type) {
|
|
715
|
+
case 'checkbox':
|
|
716
|
+
return null;
|
|
717
|
+
case 'number':
|
|
718
|
+
return null;
|
|
719
|
+
case 'hidden':
|
|
720
|
+
return 0;
|
|
721
|
+
default:
|
|
722
|
+
return '';
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
subscribeToFormChanges() {
|
|
726
|
+
this.form.valueChanges
|
|
727
|
+
.pipe(takeUntil(this.destroy$))
|
|
728
|
+
.subscribe(values => {
|
|
729
|
+
this.updateFormState();
|
|
730
|
+
});
|
|
731
|
+
this.form.statusChanges
|
|
732
|
+
.pipe(takeUntil(this.destroy$))
|
|
733
|
+
.subscribe(() => {
|
|
734
|
+
this.updateFormState();
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
updateFormState() {
|
|
738
|
+
const touched = {};
|
|
739
|
+
const errors = [];
|
|
740
|
+
this.fieldMap.forEach((field, fieldId) => {
|
|
741
|
+
const control = this.form.get(fieldId);
|
|
742
|
+
if (control) {
|
|
743
|
+
touched[fieldId] = control.touched;
|
|
744
|
+
if (control.invalid && control.touched) {
|
|
745
|
+
const fieldErrors = this.dynamicFormService.getErrorMessages(field, control.errors);
|
|
746
|
+
errors.push(...fieldErrors);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
this.formState = {
|
|
751
|
+
values: this.form.value,
|
|
752
|
+
errors,
|
|
753
|
+
touched,
|
|
754
|
+
isSubmitting: this.formState.isSubmitting,
|
|
755
|
+
isValid: this.form.valid
|
|
756
|
+
};
|
|
757
|
+
this.emitFormState();
|
|
758
|
+
}
|
|
759
|
+
emitFormState() {
|
|
760
|
+
this.formStateChange.emit({ ...this.formState });
|
|
761
|
+
}
|
|
762
|
+
showCancelButton() {
|
|
763
|
+
if (!this.config.hideCancelButton) {
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
return !this.config.hideCancelButton();
|
|
767
|
+
}
|
|
768
|
+
showSubmitButton() {
|
|
769
|
+
if (!this.config.hideSubmitButton) {
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
return !this.config.hideSubmitButton();
|
|
773
|
+
}
|
|
774
|
+
isFieldVisible(field) {
|
|
775
|
+
if (!field.conditionalDisplay) {
|
|
776
|
+
return true;
|
|
777
|
+
}
|
|
778
|
+
return field.conditionalDisplay(this.form.value);
|
|
779
|
+
}
|
|
780
|
+
isSectionVisible(section) {
|
|
781
|
+
if (!section.conditionalDisplay) {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
return section.conditionalDisplay(this.form.value);
|
|
785
|
+
}
|
|
786
|
+
isFrameVisible(frame) {
|
|
787
|
+
if (!frame.conditionalDisplay) {
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
return frame.conditionalDisplay(this.form.value);
|
|
791
|
+
}
|
|
792
|
+
onSubmit() {
|
|
793
|
+
if (this.form.invalid) {
|
|
794
|
+
this.markAllAsTouched();
|
|
795
|
+
this.updateFormState();
|
|
796
|
+
for (const frame of this.sortedFrames) {
|
|
797
|
+
for (const section of frame.sections) {
|
|
798
|
+
for (const field of section.fields) {
|
|
799
|
+
const control = this.form.get(field.id);
|
|
800
|
+
if (control && !control.valid) {
|
|
801
|
+
const component = this.componentMap.get(field.id);
|
|
802
|
+
if (component) {
|
|
803
|
+
component.focusOn();
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
this.formState.isSubmitting = true;
|
|
813
|
+
this.emitFormState();
|
|
814
|
+
const formValue = this.form.value;
|
|
815
|
+
this.formSubmit.emit(formValue);
|
|
816
|
+
// Reset submitting state after emission
|
|
817
|
+
setTimeout(() => {
|
|
818
|
+
this.formState.isSubmitting = false;
|
|
819
|
+
this.emitFormState();
|
|
820
|
+
}, 0);
|
|
821
|
+
}
|
|
822
|
+
onCancel() {
|
|
823
|
+
this.formCancel.emit();
|
|
824
|
+
}
|
|
825
|
+
markAllAsTouched() {
|
|
826
|
+
Object.keys(this.form.controls).forEach(key => {
|
|
827
|
+
const control = this.form.get(key);
|
|
828
|
+
control?.markAsTouched();
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
getFieldErrors(fieldId) {
|
|
832
|
+
const control = this.form.get(fieldId);
|
|
833
|
+
if (!control || !control.errors || !control.touched) {
|
|
834
|
+
return [];
|
|
835
|
+
}
|
|
836
|
+
const field = this.fieldMap.get(fieldId);
|
|
837
|
+
if (!field) {
|
|
838
|
+
return [];
|
|
839
|
+
}
|
|
840
|
+
return this.dynamicFormService.getErrorMessages(field, control.errors).map(e => e.message);
|
|
841
|
+
}
|
|
842
|
+
reset() {
|
|
843
|
+
this.form.reset();
|
|
844
|
+
this.formState = {
|
|
845
|
+
values: this.form.value,
|
|
846
|
+
errors: [],
|
|
847
|
+
touched: {},
|
|
848
|
+
isSubmitting: false,
|
|
849
|
+
isValid: this.form.valid
|
|
850
|
+
};
|
|
851
|
+
this.emitFormState();
|
|
852
|
+
}
|
|
853
|
+
patchValues(values) {
|
|
854
|
+
this.form.patchValue(values);
|
|
855
|
+
if (this.form.valid) {
|
|
856
|
+
this.markAllAsTouched();
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
getFormValue() {
|
|
860
|
+
return this.form.value;
|
|
861
|
+
}
|
|
862
|
+
get submitLabel() {
|
|
863
|
+
return this.config.submitLabel ?? 'Submit';
|
|
864
|
+
}
|
|
865
|
+
get cancelLabel() {
|
|
866
|
+
return this.config.cancelLabel ?? 'Cancel';
|
|
867
|
+
}
|
|
868
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormComponent, deps: [{ token: i1.BreakpointObserver }], target: i0.ɵɵFactoryTarget.Component });
|
|
869
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.18", type: DynamicFormComponent, isStandalone: true, selector: "app-dynamic-form", inputs: { config: "config", initialValues: "initialValues", allowHelpOverlay: "allowHelpOverlay", allowHelpSideBar: "allowHelpSideBar" }, outputs: { formSubmit: "formSubmit", formCancel: "formCancel", formStateChange: "formStateChange" }, viewQueries: [{ propertyName: "fieldComponents", predicate: DynamicFormFieldComponent, descendants: true }], ngImport: i0, template: "@if (config) {\r\n <div class=\"dynamic-form-container\">\r\n @if (config.title || config.description) {\r\n <div class=\"form-title\">\r\n <div class=\"title-container\">\r\n @if (config.title) {\r\n <h4>{{ config.title }}</h4>\r\n }\r\n @if (config.description) {\r\n <p class=\"form-description\">{{ config.description }}</p>\r\n }\r\n <hr class=\"title-subline\" />\r\n </div>\r\n </div>\r\n }\r\n <form [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\" novalidate>\r\n <div *ngIf=\"config.preInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"config.preInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"config.preWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"config.preWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <ng-container *ngFor=\"let frame of sortedFrames\">\r\n <div [ngClass]=\"frame.cssClass\" *ngIf=\"isFrameVisible(frame)\">\r\n <div [ngClass]=\"frame.innerFrameCssClass\">\r\n <div *ngIf=\"frame.title\" [ngClass]=\"frame.titleContainerCssClass\">\r\n <span *ngIf=\"frame.titlePrefix\" [ngClass]=\"frame.titlePrefixCssClass\">{{frame.titlePrefix}}</span>\r\n <h3 [ngClass]=\"frame.titleCssClass\">{{frame.title}}</h3>\r\n </div>\r\n <div *ngIf=\"frame.description\" class=\"frame-description\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"frame.description\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <ng-container *ngFor=\"let section of frame.sections\">\r\n <div class=\"section-wrapper\" *ngIf=\"isSectionVisible(section)\">\r\n <div class=\"section-content\">\r\n\r\n <h5 *ngIf=\"section.title != null\" class=\"section-title\">{{section.title}}</h5>\r\n <div *ngIf=\"section.preInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"section.preInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"section.preWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"section.preWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <div class=\"fields-wrapper\">\r\n <div class=\"fields-grid\">\r\n <ng-container *ngFor=\"let field of section.fields\">\r\n <ng-container *ngIf=\"field.type == 'hidden'\" [formGroup]=\"form\">\r\n <input type=\"hidden\" [formControlName]=\"field.id\" />\r\n\r\n </ng-container>\r\n <ng-container *ngIf=\"field.type != 'hidden'\">\r\n\r\n <div class=\"field-container\" [ngClass]=\"field.cssClass\" *ngIf=\"isFieldVisible(field)\">\r\n <app-dynamic-form-field [field]=\"field\"\r\n [form]=\"form\"\r\n [errors]=\"getFieldErrors(field.id)\"\r\n [allowHelpOverlay]=\"allowHelpOverlay\"\r\n [allowHelpSideBar]=\"allowHelpSideBar\">\r\n </app-dynamic-form-field>\r\n\r\n </div>\r\n </ng-container>\r\n\r\n </ng-container>\r\n </div>\r\n </div>\r\n\r\n <div *ngIf=\"section.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"section.postInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"section.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"section.postWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </ng-container>\r\n\r\n\r\n <ng-content></ng-content>\r\n <div id=\"buttoncont\" class=\"button-container\">\r\n <div class=\"button-group\">\r\n @if (showCancelButton()) {\r\n <button pButton\r\n type=\"button\"\r\n class=\"btn-cancel\"\r\n icon=\"{{config.cancelIcon ? config.cancelIcon : 'pi pi-times'}}\"\r\n iconPos=\"left\"\r\n [label]=\"cancelLabel\"\r\n [disabled]=\"formState.isSubmitting\"\r\n (click)=\"onCancel()\">\r\n </button>\r\n }\r\n @if (showSubmitButton()) {\r\n <button pButton\r\n type=\"submit\"\r\n class=\"\"\r\n icon=\"{{config.submitIcon ? config.submitIcon : 'pi pi-check'}}\"\r\n iconPos=\"right\"\r\n [label]=\"submitLabel\"\r\n [disabled]=\"formState.isSubmitting\"\r\n [loading]=\"formState.isSubmitting\">\r\n </button>\r\n }\r\n </div>\r\n </div>\r\n <div *ngIf=\"config.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">{{config.postInfo}}</p-message>\r\n </div>\r\n <div *ngIf=\"config.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">{{config.postWarning}}</p-message>\r\n </div>\r\n\r\n </form>\r\n </div>\r\n}\r\n", styles: [".dynamic-form-container{width:100%}.dynamic-form-container p-message .p-message.light-font .p-message-text{font-weight:400}.dynamic-form-container .form-description{color:#666;margin-bottom:1rem}.dynamic-form-container .form-fields-container{margin-bottom:1rem}.dynamic-form-container .form-fields-container .row{margin-bottom:.5rem}.dynamic-form-container .form-actions{margin-top:2rem;padding-top:1rem;border-top:1px solid #dee2e6}.dynamic-form-container .form-actions button{margin-left:.5rem}.dynamic-form-container .form-actions .btn-cancel{background-color:#6c757d;border-color:#6c757d}.dynamic-form-container .form-actions .btn-cancel:hover{background-color:#5a6268;border-color:#545b62}.dynamic-form-container .section-wrapper{width:100%;display:flex;justify-content:center}.dynamic-form-container .section-content{width:100%;display:flex;flex-wrap:wrap;gap:1rem;justify-content:center;padding-top:16px}.dynamic-form-container .section-title{width:100%;text-align:left;font-size:24px;font-weight:600;margin-top:8px;margin-bottom:16px}.dynamic-form-container .message-container{width:100%;display:block;margin-top:.5rem;margin-bottom:.5rem;text-align:left}.dynamic-form-container .fields-wrapper{width:100%;display:flex;justify-content:center}.dynamic-form-container .fields-grid{width:100%;display:flex;flex-wrap:wrap;gap:1rem;justify-content:left}.dynamic-form-container .field-container,.dynamic-form-container .field-container-2col,.dynamic-form-container .field-container-1col{width:100%;text-align:left}.dynamic-form-container .button-container{width:100%;display:flex;justify-content:flex-end}.dynamic-form-container .button-group{display:flex;gap:.5rem}@media (min-width: 1024px){.dynamic-form-container .field-container,.dynamic-form-container .field-container-2col{width:calc(50% - .5rem)}.dynamic-form-container .field-container-1col{width:100%}}@media (max-width: 768px){.dynamic-form-container .form-actions button{width:100%;margin:.25rem 0}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: DynamicFormFieldComponent, selector: "app-dynamic-form-field", inputs: ["field", "form", "errors", "allowHelpOverlay", "allowHelpSideBar"] }, { kind: "ngmodule", type: ButtonModule }, { kind: "directive", type: i4$1.ButtonDirective, selector: "[pButton]", inputs: ["ptButtonDirective", "hostName", "text", "plain", "raised", "size", "outlined", "rounded", "iconPos", "loadingIcon", "fluid", "label", "icon", "loading", "buttonProps", "severity"] }, { kind: "ngmodule", type: MessageModule }, { kind: "component", type: i11.Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant"], outputs: ["onClose"] }] });
|
|
870
|
+
}
|
|
871
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DynamicFormComponent, decorators: [{
|
|
872
|
+
type: Component,
|
|
873
|
+
args: [{ selector: 'app-dynamic-form', standalone: true, imports: [CommonModule, ReactiveFormsModule, DynamicFormFieldComponent, ButtonModule, MessageModule], template: "@if (config) {\r\n <div class=\"dynamic-form-container\">\r\n @if (config.title || config.description) {\r\n <div class=\"form-title\">\r\n <div class=\"title-container\">\r\n @if (config.title) {\r\n <h4>{{ config.title }}</h4>\r\n }\r\n @if (config.description) {\r\n <p class=\"form-description\">{{ config.description }}</p>\r\n }\r\n <hr class=\"title-subline\" />\r\n </div>\r\n </div>\r\n }\r\n <form [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\" novalidate>\r\n <div *ngIf=\"config.preInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"config.preInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"config.preWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"config.preWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <ng-container *ngFor=\"let frame of sortedFrames\">\r\n <div [ngClass]=\"frame.cssClass\" *ngIf=\"isFrameVisible(frame)\">\r\n <div [ngClass]=\"frame.innerFrameCssClass\">\r\n <div *ngIf=\"frame.title\" [ngClass]=\"frame.titleContainerCssClass\">\r\n <span *ngIf=\"frame.titlePrefix\" [ngClass]=\"frame.titlePrefixCssClass\">{{frame.titlePrefix}}</span>\r\n <h3 [ngClass]=\"frame.titleCssClass\">{{frame.title}}</h3>\r\n </div>\r\n <div *ngIf=\"frame.description\" class=\"frame-description\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"frame.description\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <ng-container *ngFor=\"let section of frame.sections\">\r\n <div class=\"section-wrapper\" *ngIf=\"isSectionVisible(section)\">\r\n <div class=\"section-content\">\r\n\r\n <h5 *ngIf=\"section.title != null\" class=\"section-title\">{{section.title}}</h5>\r\n <div *ngIf=\"section.preInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"section.preInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"section.preWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"section.preWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n <div class=\"fields-wrapper\">\r\n <div class=\"fields-grid\">\r\n <ng-container *ngFor=\"let field of section.fields\">\r\n <ng-container *ngIf=\"field.type == 'hidden'\" [formGroup]=\"form\">\r\n <input type=\"hidden\" [formControlName]=\"field.id\" />\r\n\r\n </ng-container>\r\n <ng-container *ngIf=\"field.type != 'hidden'\">\r\n\r\n <div class=\"field-container\" [ngClass]=\"field.cssClass\" *ngIf=\"isFieldVisible(field)\">\r\n <app-dynamic-form-field [field]=\"field\"\r\n [form]=\"form\"\r\n [errors]=\"getFieldErrors(field.id)\"\r\n [allowHelpOverlay]=\"allowHelpOverlay\"\r\n [allowHelpSideBar]=\"allowHelpSideBar\">\r\n </app-dynamic-form-field>\r\n\r\n </div>\r\n </ng-container>\r\n\r\n </ng-container>\r\n </div>\r\n </div>\r\n\r\n <div *ngIf=\"section.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">\r\n <div [innerHTML]=\"section.postInfo\"></div>\r\n </p-message>\r\n </div>\r\n <div *ngIf=\"section.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">\r\n <div [innerHTML]=\"section.postWarning\"></div>\r\n </p-message>\r\n </div>\r\n\r\n\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </ng-container>\r\n\r\n\r\n <ng-content></ng-content>\r\n <div id=\"buttoncont\" class=\"button-container\">\r\n <div class=\"button-group\">\r\n @if (showCancelButton()) {\r\n <button pButton\r\n type=\"button\"\r\n class=\"btn-cancel\"\r\n icon=\"{{config.cancelIcon ? config.cancelIcon : 'pi pi-times'}}\"\r\n iconPos=\"left\"\r\n [label]=\"cancelLabel\"\r\n [disabled]=\"formState.isSubmitting\"\r\n (click)=\"onCancel()\">\r\n </button>\r\n }\r\n @if (showSubmitButton()) {\r\n <button pButton\r\n type=\"submit\"\r\n class=\"\"\r\n icon=\"{{config.submitIcon ? config.submitIcon : 'pi pi-check'}}\"\r\n iconPos=\"right\"\r\n [label]=\"submitLabel\"\r\n [disabled]=\"formState.isSubmitting\"\r\n [loading]=\"formState.isSubmitting\">\r\n </button>\r\n }\r\n </div>\r\n </div>\r\n <div *ngIf=\"config.postInfo\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"info\">{{config.postInfo}}</p-message>\r\n </div>\r\n <div *ngIf=\"config.postWarning\" class=\"message-container\">\r\n <p-message styleClass=\"light-font\" severity=\"warn\">{{config.postWarning}}</p-message>\r\n </div>\r\n\r\n </form>\r\n </div>\r\n}\r\n", styles: [".dynamic-form-container{width:100%}.dynamic-form-container p-message .p-message.light-font .p-message-text{font-weight:400}.dynamic-form-container .form-description{color:#666;margin-bottom:1rem}.dynamic-form-container .form-fields-container{margin-bottom:1rem}.dynamic-form-container .form-fields-container .row{margin-bottom:.5rem}.dynamic-form-container .form-actions{margin-top:2rem;padding-top:1rem;border-top:1px solid #dee2e6}.dynamic-form-container .form-actions button{margin-left:.5rem}.dynamic-form-container .form-actions .btn-cancel{background-color:#6c757d;border-color:#6c757d}.dynamic-form-container .form-actions .btn-cancel:hover{background-color:#5a6268;border-color:#545b62}.dynamic-form-container .section-wrapper{width:100%;display:flex;justify-content:center}.dynamic-form-container .section-content{width:100%;display:flex;flex-wrap:wrap;gap:1rem;justify-content:center;padding-top:16px}.dynamic-form-container .section-title{width:100%;text-align:left;font-size:24px;font-weight:600;margin-top:8px;margin-bottom:16px}.dynamic-form-container .message-container{width:100%;display:block;margin-top:.5rem;margin-bottom:.5rem;text-align:left}.dynamic-form-container .fields-wrapper{width:100%;display:flex;justify-content:center}.dynamic-form-container .fields-grid{width:100%;display:flex;flex-wrap:wrap;gap:1rem;justify-content:left}.dynamic-form-container .field-container,.dynamic-form-container .field-container-2col,.dynamic-form-container .field-container-1col{width:100%;text-align:left}.dynamic-form-container .button-container{width:100%;display:flex;justify-content:flex-end}.dynamic-form-container .button-group{display:flex;gap:.5rem}@media (min-width: 1024px){.dynamic-form-container .field-container,.dynamic-form-container .field-container-2col{width:calc(50% - .5rem)}.dynamic-form-container .field-container-1col{width:100%}}@media (max-width: 768px){.dynamic-form-container .form-actions button{width:100%;margin:.25rem 0}}\n"] }]
|
|
874
|
+
}], ctorParameters: () => [{ type: i1.BreakpointObserver }], propDecorators: { config: [{
|
|
875
|
+
type: Input
|
|
876
|
+
}], initialValues: [{
|
|
877
|
+
type: Input
|
|
878
|
+
}], allowHelpOverlay: [{
|
|
879
|
+
type: Input
|
|
880
|
+
}], allowHelpSideBar: [{
|
|
881
|
+
type: Input
|
|
882
|
+
}], formSubmit: [{
|
|
883
|
+
type: Output
|
|
884
|
+
}], formCancel: [{
|
|
885
|
+
type: Output
|
|
886
|
+
}], formStateChange: [{
|
|
887
|
+
type: Output
|
|
888
|
+
}], fieldComponents: [{
|
|
889
|
+
type: ViewChildren,
|
|
890
|
+
args: [DynamicFormFieldComponent]
|
|
891
|
+
}] } });
|
|
892
|
+
|
|
893
|
+
function getComponentFromElement(el, injector, componentType) {
|
|
894
|
+
try {
|
|
895
|
+
// Get the native element
|
|
896
|
+
const nativeElement = el.nativeElement;
|
|
897
|
+
// Access Angular's internal context from the element
|
|
898
|
+
const context = nativeElement.__ngContext__;
|
|
899
|
+
if (!context) {
|
|
900
|
+
return null;
|
|
901
|
+
}
|
|
902
|
+
// The context is an array or number that references the LView
|
|
903
|
+
// We need to traverse up to find the component instance
|
|
904
|
+
let lView;
|
|
905
|
+
if (typeof context === 'number') {
|
|
906
|
+
// Context is an index into the LView array
|
|
907
|
+
lView = nativeElement.__ngContext__;
|
|
908
|
+
}
|
|
909
|
+
else if (Array.isArray(context)) {
|
|
910
|
+
lView = context;
|
|
911
|
+
}
|
|
912
|
+
// Try to find the parent component by traversing the DOM tree
|
|
913
|
+
let currentElement = nativeElement.parentElement;
|
|
914
|
+
while (currentElement) {
|
|
915
|
+
const elementContext = currentElement.__ngContext__;
|
|
916
|
+
if (elementContext) {
|
|
917
|
+
// Check if this element has a component instance
|
|
918
|
+
const lViewArray = Array.isArray(elementContext) ? elementContext : null;
|
|
919
|
+
if (lViewArray) {
|
|
920
|
+
// LView[8] typically contains the component instance
|
|
921
|
+
for (let i = 8; i < lViewArray.length; i++) {
|
|
922
|
+
const item = lViewArray[i];
|
|
923
|
+
if (item && item instanceof componentType) {
|
|
924
|
+
return item;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
currentElement = currentElement.parentElement;
|
|
930
|
+
}
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
catch (error) {
|
|
934
|
+
console.error('Error getting component from element:', error);
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/*
|
|
940
|
+
* Public API Surface of dynamic-form-lib
|
|
941
|
+
*/
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Generated bundle index. Do not edit.
|
|
945
|
+
*/
|
|
946
|
+
|
|
947
|
+
export { DynamicFormComponent, DynamicFormFieldComponent, DynamicFormService, DynamicRefDirective, getComponentFromElement };
|
|
948
|
+
//# sourceMappingURL=bcweed-dynamic-form-lib.mjs.map
|