@stemy/ngx-dynamic-form 19.8.11 → 19.8.12
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/fesm2022/stemy-ngx-dynamic-form.mjs +156 -142
- package/fesm2022/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/ngx-dynamic-form/common-types.d.ts +1 -1
- package/ngx-dynamic-form/services/dynamic-form-builder.service.d.ts +0 -1
- package/ngx-dynamic-form/utils/misc.d.ts +2 -0
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
|
@@ -118,134 +118,6 @@ function FormFieldSet(data) {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
function validationMessage(errorKey) {
|
|
122
|
-
const key = `form.error.${errorKey}`;
|
|
123
|
-
return (_, field) => {
|
|
124
|
-
const injector = field.options.formState?.injector;
|
|
125
|
-
const language = injector?.get(LANGUAGE_SERVICE);
|
|
126
|
-
return !language ? key : language.getTranslationSync(key, field);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function withName(fn, name) {
|
|
130
|
-
fn.validatorName = name;
|
|
131
|
-
return fn;
|
|
132
|
-
}
|
|
133
|
-
function validateEach(each, cb, name) {
|
|
134
|
-
return withName((control) => {
|
|
135
|
-
const value = control.value;
|
|
136
|
-
return each ? Array.isArray(value) && value.every(cb) : cb(value);
|
|
137
|
-
}, name);
|
|
138
|
-
}
|
|
139
|
-
function addFieldValidators(field, validators) {
|
|
140
|
-
field.validators = field.validators || {};
|
|
141
|
-
const validation = field.validation || {};
|
|
142
|
-
const messages = validation.messages || {};
|
|
143
|
-
if (Array.isArray(validators)) {
|
|
144
|
-
validators.forEach((validator, ix) => {
|
|
145
|
-
const name = validator.validatorName || `validator_${ix}`;
|
|
146
|
-
field.validators[name] = validator;
|
|
147
|
-
messages[name] = validationMessage(name);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else if (validators) {
|
|
151
|
-
Object.keys(validators).forEach(name => {
|
|
152
|
-
field.validators[name] = validators[name];
|
|
153
|
-
messages[name] = validationMessage(name);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
field.validation = {
|
|
157
|
-
...validation,
|
|
158
|
-
messages
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function removeFieldValidators(field, ...names) {
|
|
162
|
-
const validators = Object.assign({}, field.validators || {});
|
|
163
|
-
const validation = field.validation || {};
|
|
164
|
-
const messages = Object.assign({}, validation.messages || {});
|
|
165
|
-
names.forEach(name => {
|
|
166
|
-
delete validators[name];
|
|
167
|
-
delete messages[name];
|
|
168
|
-
});
|
|
169
|
-
field.validators = validators;
|
|
170
|
-
field.validation = {
|
|
171
|
-
...validation,
|
|
172
|
-
messages
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function jsonValidation() {
|
|
176
|
-
return withName((control) => {
|
|
177
|
-
const value = control.value;
|
|
178
|
-
if (!value)
|
|
179
|
-
return false;
|
|
180
|
-
try {
|
|
181
|
-
JSON.parse(value);
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
}, "json");
|
|
188
|
-
}
|
|
189
|
-
function requiredValidation() {
|
|
190
|
-
return withName((control) => ObjectUtils.isString(control.value) ? control.value.length > 0 : ObjectUtils.isDefined(control.value), "required");
|
|
191
|
-
}
|
|
192
|
-
function translationValidation(langs = ["de", "en"]) {
|
|
193
|
-
return withName((control) => {
|
|
194
|
-
const value = control.value;
|
|
195
|
-
if (!value || value.length == 0)
|
|
196
|
-
return false;
|
|
197
|
-
return value.findIndex(t => langs.includes(t.lang) && !t.translation) < 0;
|
|
198
|
-
}, "translation");
|
|
199
|
-
}
|
|
200
|
-
function phoneValidation() {
|
|
201
|
-
return withName((control) => {
|
|
202
|
-
const value = control.value;
|
|
203
|
-
if (!value)
|
|
204
|
-
return true;
|
|
205
|
-
const phoneRegexp = /^\d{10,12}$/;
|
|
206
|
-
return phoneRegexp.test(value);
|
|
207
|
-
}, "phone");
|
|
208
|
-
}
|
|
209
|
-
function emailValidation() {
|
|
210
|
-
return withName((control) => {
|
|
211
|
-
const value = control.value;
|
|
212
|
-
if (!value)
|
|
213
|
-
return true;
|
|
214
|
-
const emailRegexp = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/g;
|
|
215
|
-
return emailRegexp.test(value);
|
|
216
|
-
}, "email");
|
|
217
|
-
}
|
|
218
|
-
function arrayLengthValidation(min = 1, max = Number.MAX_SAFE_INTEGER) {
|
|
219
|
-
return withName((control) => {
|
|
220
|
-
const value = control.value;
|
|
221
|
-
return !Array.isArray(value) || (min <= value.length && value.length <= max);
|
|
222
|
-
}, "arrayLength");
|
|
223
|
-
}
|
|
224
|
-
function minLengthValidation(minLength, each) {
|
|
225
|
-
return validateEach(each, v => typeof v == "string" && v.length >= minLength, "minLength");
|
|
226
|
-
}
|
|
227
|
-
function maxLengthValidation(maxLength, each) {
|
|
228
|
-
return validateEach(each, v => typeof v == "string" && v.length <= maxLength, "maxLength");
|
|
229
|
-
}
|
|
230
|
-
function minValueValidation(min, each) {
|
|
231
|
-
return validateEach(each, v => {
|
|
232
|
-
if (min instanceof Date) {
|
|
233
|
-
const date = new Date(v);
|
|
234
|
-
return isNaN(date) || date >= min;
|
|
235
|
-
}
|
|
236
|
-
return v == null || v >= min;
|
|
237
|
-
}, "minValue");
|
|
238
|
-
}
|
|
239
|
-
function maxValueValidation(max, each) {
|
|
240
|
-
return validateEach(each, v => {
|
|
241
|
-
if (max instanceof Date) {
|
|
242
|
-
const date = new Date(v);
|
|
243
|
-
return isNaN(date) || date <= max;
|
|
244
|
-
}
|
|
245
|
-
return v == null || v <= max;
|
|
246
|
-
}, "maxValue");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
121
|
function replaceSpecialChars(str, to = "-") {
|
|
250
122
|
return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
|
|
251
123
|
}
|
|
@@ -405,10 +277,158 @@ function setFieldHooks(field, hooks) {
|
|
|
405
277
|
: hooks[name];
|
|
406
278
|
});
|
|
407
279
|
}
|
|
280
|
+
function isFieldVisible(field) {
|
|
281
|
+
let visible = true;
|
|
282
|
+
let current = field;
|
|
283
|
+
while (current && visible) {
|
|
284
|
+
const hiddenFn = current.props?.__hidden;
|
|
285
|
+
const injector = field.options?.formState?.injector;
|
|
286
|
+
visible = visible && (!injector || !hiddenFn?.(current, injector));
|
|
287
|
+
current = current.parent;
|
|
288
|
+
}
|
|
289
|
+
if (Array.isArray(field.fieldGroup) && field.fieldGroup.length) {
|
|
290
|
+
return visible && field.fieldGroup.some(f => isFieldVisible(f));
|
|
291
|
+
}
|
|
292
|
+
return visible;
|
|
293
|
+
}
|
|
294
|
+
function isFieldHidden(field) {
|
|
295
|
+
return !isFieldVisible(field);
|
|
296
|
+
}
|
|
408
297
|
const MIN_INPUT_NUM = -1999999999;
|
|
409
298
|
const MAX_INPUT_NUM = 1999999999;
|
|
410
299
|
const EDITOR_FORMATS = ["php", "json", "html", "css", "scss"];
|
|
411
300
|
|
|
301
|
+
function validationMessage(errorKey) {
|
|
302
|
+
const key = `form.error.${errorKey}`;
|
|
303
|
+
return (_, field) => {
|
|
304
|
+
const injector = field.options.formState?.injector;
|
|
305
|
+
const language = injector?.get(LANGUAGE_SERVICE);
|
|
306
|
+
return !language ? key : language.getTranslationSync(key, field);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function withName(fn, name) {
|
|
310
|
+
const mainFn = (control, field) => {
|
|
311
|
+
return isFieldHidden(field) || fn(control, field);
|
|
312
|
+
};
|
|
313
|
+
mainFn.validatorName = name;
|
|
314
|
+
return mainFn;
|
|
315
|
+
}
|
|
316
|
+
function validateEach(each, cb, name) {
|
|
317
|
+
return withName((control) => {
|
|
318
|
+
const value = control.value;
|
|
319
|
+
return each ? Array.isArray(value) && value.every(cb) : cb(value);
|
|
320
|
+
}, name);
|
|
321
|
+
}
|
|
322
|
+
function addFieldValidators(field, validators) {
|
|
323
|
+
field.validators = field.validators || {};
|
|
324
|
+
const validation = field.validation || {};
|
|
325
|
+
const messages = validation.messages || {};
|
|
326
|
+
if (Array.isArray(validators)) {
|
|
327
|
+
validators.forEach((validator, ix) => {
|
|
328
|
+
const name = validator.validatorName || `validator_${ix}`;
|
|
329
|
+
field.validators[name] = validator;
|
|
330
|
+
messages[name] = validationMessage(name);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
else if (validators) {
|
|
334
|
+
Object.keys(validators).forEach(name => {
|
|
335
|
+
field.validators[name] = validators[name];
|
|
336
|
+
messages[name] = validationMessage(name);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
field.validation = {
|
|
340
|
+
...validation,
|
|
341
|
+
messages
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function removeFieldValidators(field, ...names) {
|
|
345
|
+
const validators = Object.assign({}, field.validators || {});
|
|
346
|
+
const validation = field.validation || {};
|
|
347
|
+
const messages = Object.assign({}, validation.messages || {});
|
|
348
|
+
names.forEach(name => {
|
|
349
|
+
delete validators[name];
|
|
350
|
+
delete messages[name];
|
|
351
|
+
});
|
|
352
|
+
field.validators = validators;
|
|
353
|
+
field.validation = {
|
|
354
|
+
...validation,
|
|
355
|
+
messages
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function jsonValidation() {
|
|
359
|
+
return withName((control) => {
|
|
360
|
+
const value = control.value;
|
|
361
|
+
if (!value)
|
|
362
|
+
return false;
|
|
363
|
+
try {
|
|
364
|
+
JSON.parse(value);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
}, "json");
|
|
371
|
+
}
|
|
372
|
+
function requiredValidation() {
|
|
373
|
+
return withName((control) => ObjectUtils.isString(control.value) ? control.value.length > 0 : ObjectUtils.isDefined(control.value), "required");
|
|
374
|
+
}
|
|
375
|
+
function translationValidation(langs = ["de", "en"]) {
|
|
376
|
+
return withName((control) => {
|
|
377
|
+
const value = control.value;
|
|
378
|
+
if (!value || value.length == 0)
|
|
379
|
+
return false;
|
|
380
|
+
return value.findIndex(t => langs.includes(t.lang) && !t.translation) < 0;
|
|
381
|
+
}, "translation");
|
|
382
|
+
}
|
|
383
|
+
function phoneValidation() {
|
|
384
|
+
return withName((control) => {
|
|
385
|
+
const value = control.value;
|
|
386
|
+
if (!value)
|
|
387
|
+
return true;
|
|
388
|
+
const phoneRegexp = /^\d{10,12}$/;
|
|
389
|
+
return phoneRegexp.test(value);
|
|
390
|
+
}, "phone");
|
|
391
|
+
}
|
|
392
|
+
function emailValidation() {
|
|
393
|
+
return withName((control) => {
|
|
394
|
+
const value = control.value;
|
|
395
|
+
if (!value)
|
|
396
|
+
return true;
|
|
397
|
+
const emailRegexp = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/g;
|
|
398
|
+
return emailRegexp.test(value);
|
|
399
|
+
}, "email");
|
|
400
|
+
}
|
|
401
|
+
function arrayLengthValidation(min = 1, max = Number.MAX_SAFE_INTEGER) {
|
|
402
|
+
return withName((control) => {
|
|
403
|
+
const value = control.value;
|
|
404
|
+
return !Array.isArray(value) || (min <= value.length && value.length <= max);
|
|
405
|
+
}, "arrayLength");
|
|
406
|
+
}
|
|
407
|
+
function minLengthValidation(minLength, each) {
|
|
408
|
+
return validateEach(each, v => typeof v == "string" && v.length >= minLength, "minLength");
|
|
409
|
+
}
|
|
410
|
+
function maxLengthValidation(maxLength, each) {
|
|
411
|
+
return validateEach(each, v => typeof v == "string" && v.length <= maxLength, "maxLength");
|
|
412
|
+
}
|
|
413
|
+
function minValueValidation(min, each) {
|
|
414
|
+
return validateEach(each, v => {
|
|
415
|
+
if (min instanceof Date) {
|
|
416
|
+
const date = new Date(v);
|
|
417
|
+
return isNaN(date) || date >= min;
|
|
418
|
+
}
|
|
419
|
+
return v == null || v >= min;
|
|
420
|
+
}, "minValue");
|
|
421
|
+
}
|
|
422
|
+
function maxValueValidation(max, each) {
|
|
423
|
+
return validateEach(each, v => {
|
|
424
|
+
if (max instanceof Date) {
|
|
425
|
+
const date = new Date(v);
|
|
426
|
+
return isNaN(date) || date <= max;
|
|
427
|
+
}
|
|
428
|
+
return v == null || v <= max;
|
|
429
|
+
}, "maxValue");
|
|
430
|
+
}
|
|
431
|
+
|
|
412
432
|
class ModelUtils {
|
|
413
433
|
static getLanguages(language) {
|
|
414
434
|
return async () => {
|
|
@@ -896,7 +916,7 @@ class DynamicFormBuilderService {
|
|
|
896
916
|
}
|
|
897
917
|
// Exceptional case, to be able to have an "empty" label element in the HTML just to fill the space.
|
|
898
918
|
if (label === " ")
|
|
899
|
-
return "
|
|
919
|
+
return "\u200B";
|
|
900
920
|
const pathPrefix = options.legacyLabels
|
|
901
921
|
? String(legacyPrefix || labelPrefix)
|
|
902
922
|
: String(parent?.props?.label || labelPrefix);
|
|
@@ -948,8 +968,7 @@ class DynamicFormBuilderService {
|
|
|
948
968
|
return !!disabled(target, this.injector);
|
|
949
969
|
},
|
|
950
970
|
"props.hidden": target => {
|
|
951
|
-
|
|
952
|
-
return !!hidden(target, this.injector);
|
|
971
|
+
return isFieldHidden(target);
|
|
953
972
|
}
|
|
954
973
|
}
|
|
955
974
|
};
|
|
@@ -963,13 +982,6 @@ class DynamicFormBuilderService {
|
|
|
963
982
|
this.setExpressions(field, options);
|
|
964
983
|
return field;
|
|
965
984
|
}
|
|
966
|
-
shouldDisplay(field) {
|
|
967
|
-
const display = field.props?.hidden !== true;
|
|
968
|
-
if (Array.isArray(field.fieldGroup) && field.fieldGroup.length) {
|
|
969
|
-
return display && field.fieldGroup.some(f => this.shouldDisplay(f));
|
|
970
|
-
}
|
|
971
|
-
return display;
|
|
972
|
-
}
|
|
973
985
|
isValid(field) {
|
|
974
986
|
const control = field.formControl;
|
|
975
987
|
const valid = field.key && control ? (control.disabled || control.valid) !== false : true;
|
|
@@ -980,7 +992,7 @@ class DynamicFormBuilderService {
|
|
|
980
992
|
}
|
|
981
993
|
setExpressions(field, options) {
|
|
982
994
|
const expressions = {
|
|
983
|
-
display: target =>
|
|
995
|
+
display: target => isFieldVisible(target),
|
|
984
996
|
valid: target => this.isValid(target),
|
|
985
997
|
className: (target) => {
|
|
986
998
|
if (!target.display) {
|
|
@@ -1777,9 +1789,11 @@ class DynamicFormComponent {
|
|
|
1777
1789
|
legacyLabels: this.legacyLabels(),
|
|
1778
1790
|
testId: this.testId(),
|
|
1779
1791
|
};
|
|
1780
|
-
const fields = this.fields() || this.builder.resolveFormFields(this.data()?.constructor, null, options);
|
|
1781
1792
|
return [
|
|
1782
|
-
this.builder.createFormGroup(null,
|
|
1793
|
+
this.builder.createFormGroup(null, parent => {
|
|
1794
|
+
const fields = this.fields() || this.builder.resolveFormFields(this.data()?.constructor, parent, options);
|
|
1795
|
+
return this.builder.createFieldSets(fields, parent, options);
|
|
1796
|
+
}, {
|
|
1783
1797
|
label: "",
|
|
1784
1798
|
useTabs: this.useTabs(),
|
|
1785
1799
|
hidden: false,
|
|
@@ -2105,5 +2119,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
2105
2119
|
* Generated bundle index. Do not edit.
|
|
2106
2120
|
*/
|
|
2107
2121
|
|
|
2108
|
-
export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, convertToNumber, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, setFieldValue, translationValidation };
|
|
2122
|
+
export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, convertToNumber, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, isFieldHidden, isFieldVisible, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, setFieldValue, translationValidation };
|
|
2109
2123
|
//# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map
|