@olafvv/ngx-dynamic-form 19.0.1 → 20.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -204
- package/fesm2022/olafvv-ngx-dynamic-form.mjs +289 -357
- package/fesm2022/olafvv-ngx-dynamic-form.mjs.map +1 -1
- package/index.d.ts +561 -3
- package/package.json +5 -5
- package/lib/components/dynamic-form/dynamic-form.component.d.ts +0 -31
- package/lib/components/dynamic-form-field/dynamic-form-field.component.d.ts +0 -49
- package/lib/controls/button/dynamic-button.component.d.ts +0 -11
- package/lib/controls/button/dynamic-button.model.d.ts +0 -26
- package/lib/controls/button-toggles/dynamic-button-toggles.component.d.ts +0 -13
- package/lib/controls/button-toggles/dynamic-button-toggles.model.d.ts +0 -14
- package/lib/controls/checkbox/dynamic-checkbox.component.d.ts +0 -13
- package/lib/controls/checkbox/dynamic-checkbox.model.d.ts +0 -15
- package/lib/controls/controls.d.ts +0 -9
- package/lib/controls/datepicker/dynamic-datepicker.component.d.ts +0 -13
- package/lib/controls/datepicker/dynamic-datepicker.model.d.ts +0 -21
- package/lib/controls/input/dynamic-input.component.d.ts +0 -19
- package/lib/controls/input/dynamic-input.model.d.ts +0 -35
- package/lib/controls/radio-group/dynamic-radio-group.component.d.ts +0 -13
- package/lib/controls/radio-group/dynamic-radio-group.model.d.ts +0 -14
- package/lib/controls/readonly/dynamic-readonly.component.d.ts +0 -10
- package/lib/controls/readonly/dynamic-readonly.model.d.ts +0 -9
- package/lib/controls/select/dynamic-select.component.d.ts +0 -13
- package/lib/controls/select/dynamic-select.model.d.ts +0 -19
- package/lib/controls/textarea/dynamic-textarea.component.d.ts +0 -18
- package/lib/controls/textarea/dynamic-textarea.model.d.ts +0 -46
- package/lib/models/classes/dynamic-form-field-base.d.ts +0 -23
- package/lib/models/classes/dynamic-form-field-model.d.ts +0 -26
- package/lib/models/classes/dynamic-form-field-option-model.d.ts +0 -41
- package/lib/models/classes/dynamic-form-field-value-model.d.ts +0 -33
- package/lib/models/classes/dynamic-form-validators.d.ts +0 -48
- package/lib/models/constants/dynamic-relations.const.d.ts +0 -15
- package/lib/models/index.d.ts +0 -11
- package/lib/models/interfaces/dynamic-form-field-config.interface.d.ts +0 -68
- package/lib/models/interfaces/dynamic-form-field-event.interface.d.ts +0 -10
- package/lib/models/interfaces/dynamic-form-field-relation.interface.d.ts +0 -28
- package/lib/models/interfaces/dynamic-form-validator.interface.d.ts +0 -6
- package/lib/models/tokens/dynamic-form-field-map-fn.token.d.ts +0 -2
- package/lib/models/types/dynamic-form-config.type.d.ts +0 -2
- package/lib/models/types/related-form-controls.type.d.ts +0 -4
- package/lib/services/dynamic-form-relations.service.d.ts +0 -26
- package/lib/services/dynamic-form.service.d.ts +0 -46
- package/lib/services/dynamic-validations.service.d.ts +0 -20
- package/public-api.d.ts +0 -4
package/index.d.ts
CHANGED
|
@@ -1,5 +1,563 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { WritableSignal, InputSignal, InjectionToken, Type } from '@angular/core';
|
|
3
|
+
import { ValidatorFn, FormGroup, AbstractControl, FormControl, FormBuilder } from '@angular/forms';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
declare enum RelationActionType {
|
|
7
|
+
DISABLED = "DISABLED",
|
|
8
|
+
ENABLED = "ENABLED",
|
|
9
|
+
HIDDEN = "HIDDEN",
|
|
10
|
+
VISIBLE = "VISIBLE",
|
|
11
|
+
REQUIRED = "REQUIRED",
|
|
12
|
+
OPTIONAL = "OPTIONAL"
|
|
13
|
+
}
|
|
14
|
+
declare enum RelationOperator {
|
|
15
|
+
AND = "AND",
|
|
16
|
+
OR = "OR"
|
|
17
|
+
}
|
|
18
|
+
type RelationCondition = {
|
|
19
|
+
/** Name of a field in the same form this field is depended on */
|
|
20
|
+
fieldName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Path to the related field.
|
|
23
|
+
* This must be used when working with nested FormGroups and you want to relate a field in a different group.
|
|
24
|
+
*/
|
|
25
|
+
path?: string;
|
|
26
|
+
/** Method that returns true when the condition is met. The passed parameter is the value of the depended field */
|
|
27
|
+
value: (val: any) => boolean;
|
|
28
|
+
};
|
|
29
|
+
type DynamicFormFieldRelation = {
|
|
30
|
+
actionType: RelationActionType;
|
|
31
|
+
conditions: RelationCondition[];
|
|
32
|
+
operator?: RelationOperator;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type DynamicFormValidator = {
|
|
36
|
+
name: string;
|
|
37
|
+
validator: ValidatorFn;
|
|
38
|
+
message?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
1
41
|
/**
|
|
2
|
-
*
|
|
42
|
+
* Base configuration object for each Dynamic Form Field.
|
|
43
|
+
* Expects a generic type describing the type of the value the control holds.
|
|
3
44
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
45
|
+
type DynamicFormFieldConfig = {
|
|
46
|
+
/**
|
|
47
|
+
* Name used as FormControlName
|
|
48
|
+
* @required
|
|
49
|
+
*/
|
|
50
|
+
name: string;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the control has to be disabled.
|
|
53
|
+
* Default value is false.
|
|
54
|
+
* @optional
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the control should be hidden.
|
|
59
|
+
* Default value is false
|
|
60
|
+
* @optional
|
|
61
|
+
*/
|
|
62
|
+
hidden?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Adds an id attribute to the FormControl.
|
|
65
|
+
* When not provided, the required 'name' property is used as id
|
|
66
|
+
* @optional
|
|
67
|
+
*/
|
|
68
|
+
id?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Used as mat-label when provided
|
|
71
|
+
* @optional
|
|
72
|
+
*/
|
|
73
|
+
label?: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* Hint text underneath the FormControl
|
|
76
|
+
* @optional
|
|
77
|
+
*/
|
|
78
|
+
hint?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Array of Dynamic Form Validators
|
|
81
|
+
* @optional
|
|
82
|
+
*/
|
|
83
|
+
validators?: DynamicFormValidator[];
|
|
84
|
+
/**
|
|
85
|
+
* Array of Dynamic Form Relations
|
|
86
|
+
* @optional
|
|
87
|
+
*/
|
|
88
|
+
relations?: DynamicFormFieldRelation[];
|
|
89
|
+
/**
|
|
90
|
+
* Event name for the control to update on.
|
|
91
|
+
* This will determine when Angular is checking the validators
|
|
92
|
+
* Possible values:
|
|
93
|
+
* - `change`: on every change event on the FormControl
|
|
94
|
+
* - `blur`: on the blur event of the FormControl
|
|
95
|
+
* - `submit`: when the parent form of the FormControl is submitted
|
|
96
|
+
*
|
|
97
|
+
* Default value is 'blur'.
|
|
98
|
+
* @optional
|
|
99
|
+
*/
|
|
100
|
+
updateOn?: 'submit' | 'blur' | 'change';
|
|
101
|
+
/**
|
|
102
|
+
* Sets the width of the field, based on percentages. Default value is 100.
|
|
103
|
+
* @optional
|
|
104
|
+
*/
|
|
105
|
+
width?: number;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Base class for all DynamicFormFields
|
|
110
|
+
*/
|
|
111
|
+
declare abstract class DynamicFormFieldModel {
|
|
112
|
+
id: string;
|
|
113
|
+
width: number;
|
|
114
|
+
label: string | null;
|
|
115
|
+
name: string;
|
|
116
|
+
hint: string | null;
|
|
117
|
+
validators: DynamicFormValidator[];
|
|
118
|
+
updateOn: 'submit' | 'blur' | 'change';
|
|
119
|
+
relations: DynamicFormFieldRelation[] | null;
|
|
120
|
+
disabledChange: Observable<boolean>;
|
|
121
|
+
abstract readonly type: string;
|
|
122
|
+
private readonly disabled$;
|
|
123
|
+
private readonly $hidden;
|
|
124
|
+
constructor(config: DynamicFormFieldConfig);
|
|
125
|
+
get disabled(): boolean;
|
|
126
|
+
set disabled(disable: boolean);
|
|
127
|
+
get hidden(): boolean;
|
|
128
|
+
set hidden(hidden: boolean);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type DynamicFormConfig = DynamicFormFieldModel[][];
|
|
132
|
+
|
|
133
|
+
declare class DynamicFormComponent {
|
|
134
|
+
group: i0.InputSignal<FormGroup<any>>;
|
|
135
|
+
formConfig: i0.InputSignal<DynamicFormConfig>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the formConfig as flat array.
|
|
138
|
+
*/
|
|
139
|
+
get flatFormConfig(): DynamicFormFieldModel[];
|
|
140
|
+
/**
|
|
141
|
+
* Get the current value of the form.
|
|
142
|
+
* @param includeDisabledFields Include the disabled fields of the form, is enabled by default
|
|
143
|
+
*/
|
|
144
|
+
getFormValue<T = unknown>(includeDisabledFields?: boolean): T;
|
|
145
|
+
/**
|
|
146
|
+
* Provides an Observable to listen to changes of a specific field in the form.
|
|
147
|
+
*
|
|
148
|
+
* @param name Name of the field
|
|
149
|
+
* @returns Observable<unknown>
|
|
150
|
+
*/
|
|
151
|
+
onControlChange(name: string): Observable<unknown>;
|
|
152
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormComponent, never>;
|
|
153
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "dynamic-form", never, { "group": { "alias": "group"; "required": true; "isSignal": true; }; "formConfig": { "alias": "formConfig"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface DynamicFormFieldValueConfig<T> extends DynamicFormFieldConfig {
|
|
157
|
+
/**
|
|
158
|
+
* The value of the control.
|
|
159
|
+
* This value will change when the control is used.
|
|
160
|
+
* @optional
|
|
161
|
+
*/
|
|
162
|
+
value?: T;
|
|
163
|
+
/**
|
|
164
|
+
* The default value of the control when initializing or resetting the control.
|
|
165
|
+
* @optional
|
|
166
|
+
*/
|
|
167
|
+
defaultValue?: T;
|
|
168
|
+
/**
|
|
169
|
+
* A function that gets called everytime the value of the control changes.
|
|
170
|
+
* Passes the value of the control as parameter.
|
|
171
|
+
* If you don't want to get an event on every keystroke without delay, use the ReactiveFormsModule `valueChanges` Observable
|
|
172
|
+
* @optional
|
|
173
|
+
*/
|
|
174
|
+
valueChanged?: (val: T | null) => any;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Base class for a DynamicFormField with a value
|
|
178
|
+
*/
|
|
179
|
+
declare abstract class DynamicFormFieldValueModel<T = unknown> extends DynamicFormFieldModel {
|
|
180
|
+
defaultValue: T | null;
|
|
181
|
+
private _value$;
|
|
182
|
+
private _valueChanged;
|
|
183
|
+
constructor(config: DynamicFormFieldValueConfig<T>);
|
|
184
|
+
get value(): T | null;
|
|
185
|
+
set value(val: T | null);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
type DynamicOptionList<T> = DynamicFormFieldOption<T>[] | Observable<DynamicFormFieldOption<T>[]>;
|
|
189
|
+
type DynamicGroupedOptionList<T> = DynamicFormFieldOptionGroup<T>[] | Observable<DynamicFormFieldOptionGroup<T>[]>;
|
|
190
|
+
/**
|
|
191
|
+
* Interface for the objects inside a list of options of Dynamic FormField
|
|
192
|
+
*/
|
|
193
|
+
interface DynamicFormFieldOption<T> {
|
|
194
|
+
/** The text shown as label */
|
|
195
|
+
label: string;
|
|
196
|
+
/** Extra line of text shown as subtitle */
|
|
197
|
+
subTitle?: string;
|
|
198
|
+
/** The value the option holds */
|
|
199
|
+
value: T;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Interface for a group op options inside a Dynamic FormField (optgroup)
|
|
203
|
+
*/
|
|
204
|
+
interface DynamicFormFieldOptionGroup<T> {
|
|
205
|
+
name: string;
|
|
206
|
+
options: DynamicFormFieldOption<T>[];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Base interface for any DynamicFormFieldConfig with options (e.g. DynamicSelectConfig or DynamicAutocompleteConfig).
|
|
210
|
+
*/
|
|
211
|
+
interface DynamicFormFieldOptionConfig<T> extends DynamicFormFieldValueConfig<T> {
|
|
212
|
+
options?: DynamicOptionList<T>;
|
|
213
|
+
groupedOptions?: DynamicGroupedOptionList<T>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Base class for any DynamicFormField with options (e.g. DynamicSelect or DynamicAutocomplete)
|
|
217
|
+
*/
|
|
218
|
+
declare abstract class DynamicFormFieldOptionModel<T> extends DynamicFormFieldValueModel<T> {
|
|
219
|
+
options$: Observable<DynamicFormFieldOption<T>[]>;
|
|
220
|
+
groupedOptions$: Observable<DynamicFormFieldOptionGroup<T>[]>;
|
|
221
|
+
private _options;
|
|
222
|
+
private _groupedOptions;
|
|
223
|
+
constructor(config: DynamicFormFieldOptionConfig<T>);
|
|
224
|
+
private setOptions;
|
|
225
|
+
private setGroupedOptions;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
declare const DYNAMIC_FORM_FIELD_BUTTON_TOGGLES = "button-toggles";
|
|
229
|
+
type DynamicButtonTogglesConfig = Omit<DynamicFormFieldOptionConfig<string | number | null>, 'label'> & {
|
|
230
|
+
/** Whether to allow multiple options to be selected. Default is false */
|
|
231
|
+
multiple?: boolean;
|
|
232
|
+
/** Whether the toggle group is vertical. Default is false */
|
|
233
|
+
vertical?: boolean;
|
|
234
|
+
};
|
|
235
|
+
declare class DynamicButtonToggles extends DynamicFormFieldOptionModel<string | number | null> {
|
|
236
|
+
multiple: boolean;
|
|
237
|
+
vertical: boolean;
|
|
238
|
+
readonly type: string;
|
|
239
|
+
constructor(config: DynamicButtonTogglesConfig);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
declare const DYNAMIC_FORM_FIELD_BUTTON = "button";
|
|
243
|
+
type OmittedProperties = 'hint' | 'validators' | 'updateOn';
|
|
244
|
+
/**
|
|
245
|
+
* @TODO icon support
|
|
246
|
+
*/
|
|
247
|
+
type DynamicButtonConfig = Omit<DynamicFormFieldConfig, OmittedProperties> & {
|
|
248
|
+
/**
|
|
249
|
+
* Label shown inside the button
|
|
250
|
+
*/
|
|
251
|
+
label: string;
|
|
252
|
+
/**
|
|
253
|
+
* Function called when the button is clicked.
|
|
254
|
+
* Provides no parameters.
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
clicked: () => any;
|
|
258
|
+
};
|
|
259
|
+
declare class DynamicButton extends DynamicFormFieldModel {
|
|
260
|
+
label: string | null;
|
|
261
|
+
clicked: () => any;
|
|
262
|
+
readonly type = "button";
|
|
263
|
+
constructor(config: DynamicButtonConfig);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
declare const DYNAMIC_FORM_FIELD_CHECKBOX = "checkbox";
|
|
267
|
+
type DynamicCheckboxConfig = DynamicFormFieldValueConfig<boolean> & {
|
|
268
|
+
labelPosition?: 'before' | 'after';
|
|
269
|
+
indeterminate?: boolean;
|
|
270
|
+
};
|
|
271
|
+
declare class DynamicCheckbox extends DynamicFormFieldValueModel<boolean> {
|
|
272
|
+
labelPosition: 'before' | 'after';
|
|
273
|
+
indeterminate: boolean;
|
|
274
|
+
readonly type: string;
|
|
275
|
+
constructor(config: DynamicCheckboxConfig);
|
|
276
|
+
get checked(): boolean;
|
|
277
|
+
set checked(checked: boolean);
|
|
278
|
+
toggle(): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare const DYNAMIC_FORM_FIELD_DATEPICKER = "datepicker";
|
|
282
|
+
type DynamicDatepickerControlValue = Date | object | string | null;
|
|
283
|
+
type DynamicDatepickerConfig = DynamicFormFieldValueConfig<DynamicDatepickerControlValue> & {
|
|
284
|
+
/** Maximum date selectable in the datepicker */
|
|
285
|
+
max?: DynamicDatepickerControlValue;
|
|
286
|
+
/** Minimum date selectable in the datepicker */
|
|
287
|
+
min?: DynamicDatepickerControlValue;
|
|
288
|
+
/** The initial date visible inside the datepicker when opening the picker */
|
|
289
|
+
startAt?: DynamicDatepickerControlValue;
|
|
290
|
+
/** The view the picker is initializing when opening */
|
|
291
|
+
startView?: 'month' | 'year' | 'multi-year';
|
|
292
|
+
};
|
|
293
|
+
declare class DynamicDatepicker extends DynamicFormFieldValueModel<DynamicDatepickerControlValue> {
|
|
294
|
+
max: DynamicDatepickerControlValue | null;
|
|
295
|
+
min: DynamicDatepickerControlValue | null;
|
|
296
|
+
startAt: DynamicDatepickerControlValue | null;
|
|
297
|
+
startView: 'month' | 'year' | 'multi-year';
|
|
298
|
+
readonly type = "datepicker";
|
|
299
|
+
constructor(config: DynamicDatepickerConfig);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
declare const DYNAMIC_FORM_FIELD_INPUT = "input";
|
|
303
|
+
type HtmlInputType = 'text' | 'number' | 'tel' | 'email' | 'password' | 'date' | 'time' | 'color';
|
|
304
|
+
type DynamicInputValue = string | number | Date | null;
|
|
305
|
+
type DynamicInputConfig = DynamicFormFieldValueConfig<DynamicInputValue> & {
|
|
306
|
+
inputType?: HtmlInputType;
|
|
307
|
+
placeholder?: string;
|
|
308
|
+
max?: number;
|
|
309
|
+
min?: number;
|
|
310
|
+
maxLength?: number;
|
|
311
|
+
minLength?: number;
|
|
312
|
+
step?: number;
|
|
313
|
+
pattern?: string | RegExp;
|
|
314
|
+
autocomplete?: 'on' | 'off';
|
|
315
|
+
prefix?: string;
|
|
316
|
+
hideClearIcon?: boolean;
|
|
317
|
+
showLoader?: WritableSignal<boolean>;
|
|
318
|
+
};
|
|
319
|
+
declare class DynamicInput extends DynamicFormFieldValueModel<DynamicInputValue> {
|
|
320
|
+
inputType: HtmlInputType;
|
|
321
|
+
placeholder: string;
|
|
322
|
+
max: number | null;
|
|
323
|
+
min: number | null;
|
|
324
|
+
maxLength: number | null;
|
|
325
|
+
minLength: number | null;
|
|
326
|
+
step: number | null;
|
|
327
|
+
pattern: string | RegExp;
|
|
328
|
+
autocomplete: 'on' | 'off';
|
|
329
|
+
prefix: string | null;
|
|
330
|
+
hideClearIcon: boolean;
|
|
331
|
+
showLoader: WritableSignal<boolean>;
|
|
332
|
+
readonly type = "input";
|
|
333
|
+
constructor(config: DynamicInputConfig);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
declare const DYNAMIC_FORM_FIELD_RADIO_GROUP = "radio-group";
|
|
337
|
+
type DynamicRadioGroupConfig = DynamicFormFieldOptionConfig<string | number | null> & {
|
|
338
|
+
/** Placement of the option label. Default is 'before' */
|
|
339
|
+
labelPosition?: 'before' | 'after';
|
|
340
|
+
/** Whether the options are shown inline (horizontally). Default is false */
|
|
341
|
+
inline?: boolean;
|
|
342
|
+
};
|
|
343
|
+
declare class DynamicRadioGroup extends DynamicFormFieldOptionModel<string | number | null> {
|
|
344
|
+
labelPosition: 'before' | 'after';
|
|
345
|
+
inline: boolean;
|
|
346
|
+
readonly type: string;
|
|
347
|
+
constructor(config: DynamicRadioGroupConfig);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
declare const DYNAMIC_FORM_FIELD_READONLY = "readonly";
|
|
351
|
+
type DynamicReadonlyValue = string | number | null;
|
|
352
|
+
type DynamicReadonlyConfig = Omit<DynamicFormFieldValueConfig<DynamicReadonlyValue>, 'validators' | 'relations' | 'updateOn'>;
|
|
353
|
+
declare class DynamicReadonly extends DynamicFormFieldValueModel<DynamicReadonlyValue> {
|
|
354
|
+
readonly type = "readonly";
|
|
355
|
+
constructor(config: DynamicReadonlyConfig);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
declare const DYNAMIC_FORM_FIELD_SELECT = "select";
|
|
359
|
+
type DynamicSelectConfig<T = string> = DynamicFormFieldOptionConfig<T> & {
|
|
360
|
+
/**
|
|
361
|
+
* Show the native dropdown instead of the Angular Material styled dropdown
|
|
362
|
+
*/
|
|
363
|
+
native?: boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Whether it is possible to select multiple options.
|
|
366
|
+
* Default value is false
|
|
367
|
+
*/
|
|
368
|
+
multiple?: boolean;
|
|
369
|
+
};
|
|
370
|
+
declare class DynamicSelect<T = string> extends DynamicFormFieldOptionModel<T> {
|
|
371
|
+
native: boolean;
|
|
372
|
+
multiple: boolean;
|
|
373
|
+
readonly type = "select";
|
|
374
|
+
constructor(config: DynamicSelectConfig<T>);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
declare const DYNAMIC_FORM_FIELD_TEXTAREA = "textarea";
|
|
378
|
+
type DynamicTextareaValue = string | null;
|
|
379
|
+
type DynamicTextareaConfig = DynamicFormFieldValueConfig<DynamicTextareaValue> & {
|
|
380
|
+
/**
|
|
381
|
+
* Placeholder text inside the textarea.
|
|
382
|
+
* Only visible when the field is empty and in focus.
|
|
383
|
+
*/
|
|
384
|
+
placeholder?: string;
|
|
385
|
+
/**
|
|
386
|
+
* Minimum amount of characters needed in the textarea
|
|
387
|
+
*/
|
|
388
|
+
minLength?: number;
|
|
389
|
+
/**
|
|
390
|
+
* Maximum amount of characters it is possible to fill in the textarea
|
|
391
|
+
*/
|
|
392
|
+
maxLength?: number;
|
|
393
|
+
/**
|
|
394
|
+
* Enables or disabled the browser natie autocomplete bubble when the control is in focus.
|
|
395
|
+
* Default value is 'off'
|
|
396
|
+
*/
|
|
397
|
+
autocomplete?: 'on' | 'off';
|
|
398
|
+
/**
|
|
399
|
+
* Amount of rows the textarea initializes on
|
|
400
|
+
*/
|
|
401
|
+
rows?: number;
|
|
402
|
+
/**
|
|
403
|
+
* Whether the textare automatically resizes to fit its content
|
|
404
|
+
*/
|
|
405
|
+
resize?: boolean;
|
|
406
|
+
/**
|
|
407
|
+
* Maximum amount of rows the textarea show resize to
|
|
408
|
+
*/
|
|
409
|
+
resizeMaxRows?: number;
|
|
410
|
+
};
|
|
411
|
+
declare class DynamicTextarea extends DynamicFormFieldValueModel<DynamicTextareaValue> {
|
|
412
|
+
placeholder: string;
|
|
413
|
+
minLength: number | null;
|
|
414
|
+
maxLength: number | null;
|
|
415
|
+
autocomplete: 'on' | 'off';
|
|
416
|
+
rows: number;
|
|
417
|
+
resize: boolean;
|
|
418
|
+
resizeMaxRows: number | null;
|
|
419
|
+
readonly type = "textarea";
|
|
420
|
+
constructor(config: DynamicTextareaConfig);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
interface DynamicFormField<M extends DynamicFormFieldModel = DynamicFormFieldModel> {
|
|
424
|
+
group: InputSignal<FormGroup>;
|
|
425
|
+
model: InputSignal<M>;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Base class for the DynamicFormField component classes
|
|
429
|
+
*/
|
|
430
|
+
declare abstract class DynamicFormFieldBase<M extends DynamicFormFieldModel = DynamicFormFieldModel> implements DynamicFormField<M> {
|
|
431
|
+
abstract group: InputSignal<FormGroup>;
|
|
432
|
+
abstract model: InputSignal<M>;
|
|
433
|
+
get id(): string;
|
|
434
|
+
get control(): AbstractControl;
|
|
435
|
+
get isValid(): boolean;
|
|
436
|
+
get isInvalid(): boolean;
|
|
437
|
+
resetControl(): void;
|
|
438
|
+
hasError(name: string): boolean;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
declare class DynamicFormValidators {
|
|
442
|
+
/**
|
|
443
|
+
* Default email validator, the value of the control has to be a valid email address
|
|
444
|
+
* @param msg
|
|
445
|
+
*/
|
|
446
|
+
static email(msg?: string): DynamicFormValidator;
|
|
447
|
+
/**
|
|
448
|
+
* Default min validator, the value has to be greater or equal than the the provided number
|
|
449
|
+
* @param min number
|
|
450
|
+
* @param msg
|
|
451
|
+
*/
|
|
452
|
+
static min(min: number, msg?: string): DynamicFormValidator;
|
|
453
|
+
/**
|
|
454
|
+
* Default max validator, the value has to be less or equal than the the provided number
|
|
455
|
+
* @param max number
|
|
456
|
+
* @param msg
|
|
457
|
+
*/
|
|
458
|
+
static max(max: number, msg?: string): DynamicFormValidator;
|
|
459
|
+
/**
|
|
460
|
+
* Default minLength validator, the value has to contain a minimum amount of characters
|
|
461
|
+
* @param min number
|
|
462
|
+
* @param msg
|
|
463
|
+
*/
|
|
464
|
+
static minLength(min: number, msg?: string): DynamicFormValidator;
|
|
465
|
+
/**
|
|
466
|
+
* Default maxLength validator, the value has to contain a maximum amount of characters
|
|
467
|
+
* @param max number
|
|
468
|
+
* @param msg
|
|
469
|
+
*/
|
|
470
|
+
static maxLength(max: number, msg?: string): DynamicFormValidator;
|
|
471
|
+
/**
|
|
472
|
+
* Default pattern validator, the value of the control has to match the provided pattern
|
|
473
|
+
* @param pattern: string | RegExp
|
|
474
|
+
* @param msg
|
|
475
|
+
*/
|
|
476
|
+
static pattern(pattern: string | RegExp, msg?: string): DynamicFormValidator;
|
|
477
|
+
/**
|
|
478
|
+
* Default required validator, the control must contain a value
|
|
479
|
+
* @param msg
|
|
480
|
+
*/
|
|
481
|
+
static required(msg?: string): DynamicFormValidator;
|
|
482
|
+
/**
|
|
483
|
+
* Default requiredTrue validator, the value of the control has to be true
|
|
484
|
+
* @param msg
|
|
485
|
+
*/
|
|
486
|
+
static requiredTrue(msg?: string): DynamicFormValidator;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
declare const DYNAMIC_FORM_FIELD_MAP: InjectionToken<Record<string, Type<DynamicFormField<any>>>>;
|
|
490
|
+
|
|
491
|
+
declare class DynamicFormValidationsService {
|
|
492
|
+
/**
|
|
493
|
+
* Get all Validator Functions from the validator configuration
|
|
494
|
+
* @param validatorConfig
|
|
495
|
+
* @returns
|
|
496
|
+
*/
|
|
497
|
+
getValidatorFns(validatorConfig: DynamicFormValidator[]): ValidatorFn[];
|
|
498
|
+
/**
|
|
499
|
+
* Update the validators on a FormControl based on the provided validator configuration.
|
|
500
|
+
* This will replace any existing validators on the control or removes all validators when none provided
|
|
501
|
+
* @param validatorConfig
|
|
502
|
+
* @param control
|
|
503
|
+
*/
|
|
504
|
+
updateValidators(validatorConfig: DynamicFormValidator[], control: FormControl): void;
|
|
505
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormValidationsService, never>;
|
|
506
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormValidationsService>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
declare class DynamicFormService {
|
|
510
|
+
private customMap;
|
|
511
|
+
private fb;
|
|
512
|
+
private validatorsService;
|
|
513
|
+
constructor(customMap: Record<string, Type<DynamicFormField>>, fb: FormBuilder, validatorsService: DynamicFormValidationsService);
|
|
514
|
+
/**
|
|
515
|
+
* Check if there is a mapping provided to use custom form controls
|
|
516
|
+
* @param model
|
|
517
|
+
* @returns
|
|
518
|
+
*/
|
|
519
|
+
getCustomControlComponentType(model: DynamicFormFieldModel): Type<DynamicFormField<any>> | null;
|
|
520
|
+
/**
|
|
521
|
+
* Create a FormGroup from the provided form configuration.
|
|
522
|
+
* Returns a FormGroup.
|
|
523
|
+
* @param {DynamicFormConfig} config Configuration object of a form
|
|
524
|
+
* @returns {FormGroup}
|
|
525
|
+
*/
|
|
526
|
+
createFormGroup(config: DynamicFormConfig): FormGroup;
|
|
527
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormService, [{ optional: true; }, null, null]>;
|
|
528
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormService>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Transform any list to a list of DynamicFormFieldOption which is used in any Dynamic Form Field with options (e.g. DynamicSelect).
|
|
533
|
+
* Possible to provide the method with type definitions to define the provided list type `<T>` and desired option value type `<K>`:
|
|
534
|
+
*
|
|
535
|
+
* `dynamicFormService.toDynamicOptionList<T, K>(...)`
|
|
536
|
+
*
|
|
537
|
+
* Generic types:
|
|
538
|
+
* - T = The type of the items in the provided list
|
|
539
|
+
* - K = The type of the value inside an DynamicFormFieldOption. Default is 'string'
|
|
540
|
+
* @param arr An array of items of type T
|
|
541
|
+
* @param labelFn Callback to define the label of the options in the template
|
|
542
|
+
* @param valueFn Callback to define the value of the options. Must return a value of type K (default string)
|
|
543
|
+
* @returns
|
|
544
|
+
*/
|
|
545
|
+
declare function arrToDynamicFormOptions<T, K = string>(arr: T[], labelFn: (item: T) => string, valueFn: (item: T) => K): DynamicFormFieldOption<K>[];
|
|
546
|
+
/**
|
|
547
|
+
* Transform any Observable of a list to a list of DynamicFormFieldOption which is used in any Dynamic Form Field with options (e.g. DynamicSelect).
|
|
548
|
+
* Possible to provide the method with type definitions to define the provided list type `<T>` and desired option value type `<K>`:
|
|
549
|
+
*
|
|
550
|
+
* `dynamicFormService.toDynamicOptionList<T, K>(...)`
|
|
551
|
+
*
|
|
552
|
+
* Generic types:
|
|
553
|
+
* - T = The type of the items in the provided list
|
|
554
|
+
* - K = The type of the value inside an DynamicFormFieldOption. Default is 'string'
|
|
555
|
+
* @param obs An Observable of a list of items of type T
|
|
556
|
+
* @param labelFn Callback to define the label of the options in the template
|
|
557
|
+
* @param valueFn Callback to define the value of the options. Must return a value of type K (default string)
|
|
558
|
+
* @returns
|
|
559
|
+
*/
|
|
560
|
+
declare function obsToDynamicFormOptions<T, K = string>(obs: Observable<T[]>, labelFn: (item: T) => string, valueFn: (item: T) => K): Observable<DynamicFormFieldOption<K>[]>;
|
|
561
|
+
|
|
562
|
+
export { DYNAMIC_FORM_FIELD_BUTTON, DYNAMIC_FORM_FIELD_BUTTON_TOGGLES, DYNAMIC_FORM_FIELD_CHECKBOX, DYNAMIC_FORM_FIELD_DATEPICKER, DYNAMIC_FORM_FIELD_INPUT, DYNAMIC_FORM_FIELD_MAP, DYNAMIC_FORM_FIELD_RADIO_GROUP, DYNAMIC_FORM_FIELD_READONLY, DYNAMIC_FORM_FIELD_SELECT, DYNAMIC_FORM_FIELD_TEXTAREA, DynamicButton, DynamicButtonToggles, DynamicCheckbox, DynamicDatepicker, DynamicFormComponent, DynamicFormFieldBase, DynamicFormFieldModel, DynamicFormFieldOptionModel, DynamicFormFieldValueModel, DynamicFormService, DynamicFormValidators, DynamicInput, DynamicRadioGroup, DynamicReadonly, DynamicSelect, DynamicTextarea, RelationActionType, RelationOperator, arrToDynamicFormOptions, obsToDynamicFormOptions };
|
|
563
|
+
export type { DynamicButtonConfig, DynamicButtonTogglesConfig, DynamicCheckboxConfig, DynamicDatepickerConfig, DynamicDatepickerControlValue, DynamicFormConfig, DynamicFormField, DynamicFormFieldConfig, DynamicFormFieldOption, DynamicFormFieldOptionConfig, DynamicFormFieldOptionGroup, DynamicFormFieldRelation, DynamicFormFieldValueConfig, DynamicFormValidator, DynamicGroupedOptionList, DynamicInputConfig, DynamicInputValue, DynamicOptionList, DynamicRadioGroupConfig, DynamicReadonlyConfig, DynamicReadonlyValue, DynamicSelectConfig, DynamicTextareaConfig, DynamicTextareaValue, HtmlInputType, RelationCondition };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olafvv/ngx-dynamic-form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.1.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@angular/common": "^
|
|
6
|
-
"@angular/core": "^
|
|
7
|
-
"@angular/forms": "^
|
|
8
|
-
"@angular/material": "^
|
|
5
|
+
"@angular/common": "^20.3.16",
|
|
6
|
+
"@angular/core": "^20.3.16",
|
|
7
|
+
"@angular/forms": "^20.3.16",
|
|
8
|
+
"@angular/material": "^20.2.14",
|
|
9
9
|
"rxjs": "^7.5.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from '@angular/core';
|
|
2
|
-
import { UntypedFormGroup } from '@angular/forms';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
import { DynamicFormFieldModel } from '../../models/classes/dynamic-form-field-model';
|
|
5
|
-
import { DynamicFormFieldEvent } from '../../models/interfaces/dynamic-form-field-event.interface';
|
|
6
|
-
import { DynamicFormConfig } from '../../models/types/dynamic-form-config.type';
|
|
7
|
-
import * as i0 from "@angular/core";
|
|
8
|
-
export declare class DynamicFormComponent {
|
|
9
|
-
group: UntypedFormGroup;
|
|
10
|
-
formConfig: DynamicFormConfig;
|
|
11
|
-
change: EventEmitter<DynamicFormFieldEvent>;
|
|
12
|
-
/**
|
|
13
|
-
* Get the formConfig as flat array.
|
|
14
|
-
*/
|
|
15
|
-
get flatFormConfig(): DynamicFormFieldModel[];
|
|
16
|
-
/**
|
|
17
|
-
* Get the current value of the form.
|
|
18
|
-
* @param includeDisabledFields Include the disabled fields of the form, is enabled by default
|
|
19
|
-
*/
|
|
20
|
-
getFormValue<T = unknown>(includeDisabledFields?: boolean): T;
|
|
21
|
-
/**
|
|
22
|
-
* Provides an Observable to listen to changes of a specific field in the form.
|
|
23
|
-
*
|
|
24
|
-
* @param name Name of the field
|
|
25
|
-
* @returns Observable<unknown>
|
|
26
|
-
*/
|
|
27
|
-
onControlChange(name: string): Observable<unknown>;
|
|
28
|
-
onChange(event: DynamicFormFieldEvent): void;
|
|
29
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormComponent, never>;
|
|
30
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "dynamic-form", never, { "group": { "alias": "group"; "required": true; }; "formConfig": { "alias": "formConfig"; "required": true; }; }, { "change": "change"; }, never, never, true, never>;
|
|
31
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
|
|
2
|
-
import { UntypedFormGroup } from '@angular/forms';
|
|
3
|
-
import { DynamicFormFieldModel } from '../../models/classes/dynamic-form-field-model';
|
|
4
|
-
import { DynamicFormFieldEvent } from '../../models/interfaces/dynamic-form-field-event.interface';
|
|
5
|
-
import * as i0 from "@angular/core";
|
|
6
|
-
export declare class DynamicFormFieldComponent implements OnInit, OnDestroy {
|
|
7
|
-
componentViewContainer: ViewContainerRef;
|
|
8
|
-
model: DynamicFormFieldModel;
|
|
9
|
-
group: UntypedFormGroup;
|
|
10
|
-
change: EventEmitter<DynamicFormFieldEvent>;
|
|
11
|
-
private readonly dynamicFormService;
|
|
12
|
-
private readonly relationService;
|
|
13
|
-
private readonly cdRef;
|
|
14
|
-
private _control;
|
|
15
|
-
private _subs;
|
|
16
|
-
/** Get the instance of a control component using the injected custom method or local method */
|
|
17
|
-
private get componentType();
|
|
18
|
-
ngOnInit(): void;
|
|
19
|
-
ngOnDestroy(): void;
|
|
20
|
-
/**
|
|
21
|
-
* Finds the instance of a control component by type
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
private getControlComponentType;
|
|
25
|
-
private createFormControlComponent;
|
|
26
|
-
/**
|
|
27
|
-
* Setup all necessary subscriptions of the FormControl
|
|
28
|
-
*/
|
|
29
|
-
private setSubscriptions;
|
|
30
|
-
/**
|
|
31
|
-
* Set up all relations of the current model
|
|
32
|
-
*/
|
|
33
|
-
private setUpRelations;
|
|
34
|
-
/**
|
|
35
|
-
* Fired when the value changes of the control and updates the value inside the model
|
|
36
|
-
* @param value
|
|
37
|
-
*/
|
|
38
|
-
private onValueChange;
|
|
39
|
-
/**
|
|
40
|
-
* Enables/disabled the control based on the provided parameter.
|
|
41
|
-
* Is fired when disabled state is changed inside the model and should not be directly used outside this component.
|
|
42
|
-
* @param disabled
|
|
43
|
-
*/
|
|
44
|
-
private onDisabledChange;
|
|
45
|
-
private onChange;
|
|
46
|
-
private createDynamicFormEvent;
|
|
47
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormFieldComponent, never>;
|
|
48
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormFieldComponent, "dynamic-form-field", never, { "model": { "alias": "model"; "required": false; }; "group": { "alias": "group"; "required": false; }; }, { "change": "change"; }, never, never, true, never>;
|
|
49
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { UntypedFormGroup } from '@angular/forms';
|
|
2
|
-
import { DynamicFormFieldBase } from '../../models/classes/dynamic-form-field-base';
|
|
3
|
-
import { DynamicButton } from './dynamic-button.model';
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
export declare class DynamicButtonComponent extends DynamicFormFieldBase {
|
|
6
|
-
model: DynamicButton;
|
|
7
|
-
group: UntypedFormGroup;
|
|
8
|
-
onClick(): void;
|
|
9
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicButtonComponent, never>;
|
|
10
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicButtonComponent, "dynamic-button", never, { "model": { "alias": "model"; "required": false; }; "group": { "alias": "group"; "required": false; }; }, {}, never, never, true, never>;
|
|
11
|
-
}
|