@stemy/ngx-dynamic-form 19.9.1 → 19.9.3
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 +49 -32
- package/fesm2022/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/ngx-dynamic-form/common-types.d.ts +3 -2
- package/ngx-dynamic-form/services/dynamic-form-builder.service.d.ts +2 -1
- package/ngx-dynamic-form/utils/validation.d.ts +4 -3
- package/package.json +1 -1
- package/public_api.d.ts +2 -2
|
@@ -151,11 +151,10 @@ function convertToDateFormat(value, format) {
|
|
|
151
151
|
return value;
|
|
152
152
|
value = ObjectUtils.isDate(value) ? value : new Date(value);
|
|
153
153
|
const date = isNaN(value) ? new Date() : value;
|
|
154
|
+
const target = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString();
|
|
154
155
|
return format === "datetime-local" || format === "date-time"
|
|
155
|
-
?
|
|
156
|
-
|
|
157
|
-
.slice(0, 16)
|
|
158
|
-
: date.toISOString().slice(0, 10);
|
|
156
|
+
? target.slice(0, 16)
|
|
157
|
+
: target.slice(0, 10);
|
|
159
158
|
}
|
|
160
159
|
/**
|
|
161
160
|
* Convert value to date object with format (date, date-time)
|
|
@@ -317,9 +316,9 @@ function withName(fn, name) {
|
|
|
317
316
|
return mainFn;
|
|
318
317
|
}
|
|
319
318
|
function validateEach(each, cb, name) {
|
|
320
|
-
return withName((control) => {
|
|
319
|
+
return withName((control, field) => {
|
|
321
320
|
const value = control.value;
|
|
322
|
-
return each ? Array.isArray(value) && value.every(cb) : cb(value);
|
|
321
|
+
return each ? Array.isArray(value) && value.every(v => cb(v, field)) : cb(value, field);
|
|
323
322
|
}, name);
|
|
324
323
|
}
|
|
325
324
|
function addFieldValidators(field, validators) {
|
|
@@ -346,7 +345,7 @@ function addFieldValidators(field, validators) {
|
|
|
346
345
|
}
|
|
347
346
|
function removeFieldValidators(field, ...names) {
|
|
348
347
|
const validators = Object.assign({}, field.validators || {});
|
|
349
|
-
const validation = field.validation || {};
|
|
348
|
+
const validation = Object.assign({}, field.validation || {});
|
|
350
349
|
const messages = Object.assign({}, validation.messages || {});
|
|
351
350
|
names.forEach(name => {
|
|
352
351
|
delete validators[name];
|
|
@@ -413,8 +412,11 @@ function minLengthValidation(minLength, each) {
|
|
|
413
412
|
function maxLengthValidation(maxLength, each) {
|
|
414
413
|
return validateEach(each, v => typeof v == "string" && v.length <= maxLength, "maxLength");
|
|
415
414
|
}
|
|
416
|
-
function minValueValidation(
|
|
417
|
-
return validateEach(each, v => {
|
|
415
|
+
function minValueValidation(each) {
|
|
416
|
+
return validateEach(each, (v, f) => {
|
|
417
|
+
const type = f.props.type || "number";
|
|
418
|
+
const min = type.includes("date")
|
|
419
|
+
? convertToDate(f.props.min, type) : Number(f.props.min ?? 0);
|
|
418
420
|
if (min instanceof Date) {
|
|
419
421
|
const date = new Date(v);
|
|
420
422
|
return isNaN(date) || date >= min;
|
|
@@ -422,8 +424,11 @@ function minValueValidation(min, each) {
|
|
|
422
424
|
return v == null || v >= min;
|
|
423
425
|
}, "minValue");
|
|
424
426
|
}
|
|
425
|
-
function maxValueValidation(
|
|
426
|
-
return validateEach(each, v => {
|
|
427
|
+
function maxValueValidation(each) {
|
|
428
|
+
return validateEach(each, (v, f) => {
|
|
429
|
+
const type = f.props.type || "number";
|
|
430
|
+
const max = type.includes("date")
|
|
431
|
+
? convertToDate(f.props.max, type) : Number(f.props.max ?? 0);
|
|
427
432
|
if (max instanceof Date) {
|
|
428
433
|
const date = new Date(v);
|
|
429
434
|
return isNaN(date) || date <= max;
|
|
@@ -431,6 +436,12 @@ function maxValueValidation(max, each) {
|
|
|
431
436
|
return v == null || v <= max;
|
|
432
437
|
}, "maxValue");
|
|
433
438
|
}
|
|
439
|
+
function setFieldMinDate(field, min) {
|
|
440
|
+
setFieldDefault(field, min);
|
|
441
|
+
setFieldProp(field, "min", min);
|
|
442
|
+
setFieldValue(field, min);
|
|
443
|
+
addFieldValidators(field, [minValueValidation(field.type === "array")]);
|
|
444
|
+
}
|
|
434
445
|
|
|
435
446
|
class ModelUtils {
|
|
436
447
|
static getLanguages() {
|
|
@@ -638,6 +649,23 @@ class DynamicFormBuilderService {
|
|
|
638
649
|
return typeof itemType === "function" ? this.resolveFormFields(itemType, sp, options) : this.createFormInput("", typeof itemType === "string" ? { type: `${itemType}` } : itemType, sp, options);
|
|
639
650
|
}, data, parent, options);
|
|
640
651
|
}
|
|
652
|
+
createFieldSet(set, fields, parent, options) {
|
|
653
|
+
const id = !parent?.path ? set.id : `${parent.path}.${set.id}`;
|
|
654
|
+
return this.setExpressions({
|
|
655
|
+
id,
|
|
656
|
+
parent,
|
|
657
|
+
fieldGroup: fields,
|
|
658
|
+
wrappers: ["form-fieldset"],
|
|
659
|
+
props: {
|
|
660
|
+
label: this.getLabel(set.id, set.label, set.labelPrefix, parent, options, "title"),
|
|
661
|
+
hidden: false,
|
|
662
|
+
classes: toStringArray(set.classes),
|
|
663
|
+
layout: toStringArray(set.layout),
|
|
664
|
+
},
|
|
665
|
+
hooks: {},
|
|
666
|
+
expressions: {}
|
|
667
|
+
}, options);
|
|
668
|
+
}
|
|
641
669
|
createFieldSets(fields, parent, options, sets = []) {
|
|
642
670
|
const result = [];
|
|
643
671
|
const groups = {};
|
|
@@ -654,27 +682,12 @@ class DynamicFormBuilderService {
|
|
|
654
682
|
// If we have a fieldset name defined, then push the property fields into a group
|
|
655
683
|
if (fsName) {
|
|
656
684
|
const id = !parent?.path ? fsName : `${parent.path}.${fsName}`;
|
|
657
|
-
const set = sets.find(s => s.id === fsName);
|
|
685
|
+
const set = sets.find(s => s.id === fsName) || { id: fsName, layout: "" };
|
|
658
686
|
let fieldGroup = groups[id];
|
|
659
687
|
if (!fieldGroup) {
|
|
660
688
|
fieldGroup = [];
|
|
661
|
-
const fieldSet = {
|
|
662
|
-
id,
|
|
663
|
-
parent,
|
|
664
|
-
fieldGroup,
|
|
665
|
-
wrappers: ["form-fieldset"],
|
|
666
|
-
props: {
|
|
667
|
-
label: this.getLabel(fsName, set?.label, set?.labelPrefix, parent, options, "title"),
|
|
668
|
-
hidden: false,
|
|
669
|
-
classes: toStringArray(set?.classes),
|
|
670
|
-
layout: toStringArray(set?.layout),
|
|
671
|
-
},
|
|
672
|
-
hooks: {},
|
|
673
|
-
expressions: {}
|
|
674
|
-
};
|
|
675
|
-
this.setExpressions(fieldSet, options);
|
|
676
689
|
groups[id] = fieldGroup;
|
|
677
|
-
result.push(
|
|
690
|
+
result.push(this.createFieldSet(set, fieldGroup, parent, options));
|
|
678
691
|
}
|
|
679
692
|
fieldGroup.push(field);
|
|
680
693
|
continue;
|
|
@@ -993,7 +1006,10 @@ class DynamicFormBuilderService {
|
|
|
993
1006
|
configurable: true
|
|
994
1007
|
});
|
|
995
1008
|
// Set expressions
|
|
996
|
-
|
|
1009
|
+
const validators = ObjectUtils.isArray(data.validators)
|
|
1010
|
+
? data.validators.map(v => ReflectUtils.resolve(v, this.injector))
|
|
1011
|
+
: data.validators;
|
|
1012
|
+
addFieldValidators(field, validators);
|
|
997
1013
|
this.setExpressions(field, options);
|
|
998
1014
|
return field;
|
|
999
1015
|
}
|
|
@@ -1052,6 +1068,7 @@ class DynamicFormBuilderService {
|
|
|
1052
1068
|
field[key] = expression(field);
|
|
1053
1069
|
}
|
|
1054
1070
|
});
|
|
1071
|
+
return field;
|
|
1055
1072
|
}
|
|
1056
1073
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormBuilderService, deps: [{ token: i0.Injector }, { token: i2.EventsService }, { token: API_SERVICE }, { token: LANGUAGE_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1057
1074
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormBuilderService });
|
|
@@ -1425,10 +1442,10 @@ class DynamicFormSchemaService {
|
|
|
1425
1442
|
validators.itemsMaxLength = maxLengthValidation(items.maxLength, true);
|
|
1426
1443
|
}
|
|
1427
1444
|
if (!isNaN(items.minimum)) {
|
|
1428
|
-
validators.itemsMinValue = minValueValidation(
|
|
1445
|
+
validators.itemsMinValue = minValueValidation(true);
|
|
1429
1446
|
}
|
|
1430
1447
|
if (!isNaN(items.maximum)) {
|
|
1431
|
-
validators.itemsMaxValue = maxValueValidation(
|
|
1448
|
+
validators.itemsMaxValue = maxValueValidation(true);
|
|
1432
1449
|
}
|
|
1433
1450
|
}
|
|
1434
1451
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormSchemaService, deps: [{ token: i2.OpenApiService }, { token: i0.Injector }, { token: DynamicFormBuilderService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
@@ -2322,5 +2339,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
2322
2339
|
* Generated bundle index. Do not edit.
|
|
2323
2340
|
*/
|
|
2324
2341
|
|
|
2325
|
-
export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, 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, setFieldSerialize, setFieldValue, translationValidation };
|
|
2342
|
+
export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, 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, setFieldMinDate, setFieldProp, setFieldProps, setFieldSerialize, setFieldValue, translationValidation };
|
|
2326
2343
|
//# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map
|