@stemy/ngx-dynamic-form 19.9.31 → 19.9.33
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.
|
@@ -40,10 +40,8 @@ function defineFormControl(target, propertyKey, cb) {
|
|
|
40
40
|
const fields = ReflectUtils.getMetadata("dynamicFormFields", target) || new Set();
|
|
41
41
|
const existing = ReflectUtils.getMetadata("dynamicFormField", target, propertyKey);
|
|
42
42
|
const builder = (fb, opts, path) => {
|
|
43
|
-
const data = ObjectUtils.isFunction(existing) ? existing(fb, opts, path) : {
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
return ObjectUtils.assign(data, cb(fb, opts, path) || {});
|
|
43
|
+
const data = ObjectUtils.isFunction(existing) ? existing(fb, opts, path) : {};
|
|
44
|
+
return ObjectUtils.assign(cb(fb, opts, path) || {}, data);
|
|
47
45
|
};
|
|
48
46
|
fields.add(propertyKey);
|
|
49
47
|
ReflectUtils.defineMetadata("dynamicFormField", builder, target, propertyKey);
|
|
@@ -431,6 +429,8 @@ function maxLengthValidation(maxLength) {
|
|
|
431
429
|
}
|
|
432
430
|
function minValueValidation() {
|
|
433
431
|
return validateEach((v, f) => {
|
|
432
|
+
if (v == null)
|
|
433
|
+
return true;
|
|
434
434
|
const type = f.props.type || "number";
|
|
435
435
|
const min = type.includes("date")
|
|
436
436
|
? convertToDate(f.props.min, type) : Number(f.props.min ?? 0);
|
|
@@ -438,11 +438,13 @@ function minValueValidation() {
|
|
|
438
438
|
const date = new Date(v);
|
|
439
439
|
return isNaN(date) || date >= min;
|
|
440
440
|
}
|
|
441
|
-
return v
|
|
441
|
+
return v >= min;
|
|
442
442
|
}, "minValue");
|
|
443
443
|
}
|
|
444
444
|
function maxValueValidation() {
|
|
445
445
|
return validateEach((v, f) => {
|
|
446
|
+
if (v == null)
|
|
447
|
+
return true;
|
|
446
448
|
const type = f.props.type || "number";
|
|
447
449
|
const max = type.includes("date")
|
|
448
450
|
? convertToDate(f.props.max, type) : Number(f.props.max ?? 0);
|
|
@@ -450,7 +452,7 @@ function maxValueValidation() {
|
|
|
450
452
|
const date = new Date(v);
|
|
451
453
|
return isNaN(date) || date <= max;
|
|
452
454
|
}
|
|
453
|
-
return v
|
|
455
|
+
return v <= max;
|
|
454
456
|
}, "maxValue");
|
|
455
457
|
}
|
|
456
458
|
function enumValidation($enum) {
|
|
@@ -458,6 +460,11 @@ function enumValidation($enum) {
|
|
|
458
460
|
return $enum.includes(v);
|
|
459
461
|
}, "enum");
|
|
460
462
|
}
|
|
463
|
+
function equalsValidation(target) {
|
|
464
|
+
return validateEach(v => {
|
|
465
|
+
return v === target;
|
|
466
|
+
}, "equals");
|
|
467
|
+
}
|
|
461
468
|
function setFieldMinDate(field, min, setValue = true) {
|
|
462
469
|
setFieldProp(field, "min", min);
|
|
463
470
|
addFieldValidators(field, [minValueValidation()]);
|
|
@@ -805,7 +812,6 @@ class DynamicFormBuilderService {
|
|
|
805
812
|
setFieldProp(target, "options", options instanceof Observable
|
|
806
813
|
? options
|
|
807
814
|
: controlValues(root).pipe(combineLatestWith(this.language), switchMap(async (a, b) => {
|
|
808
|
-
console.log(a, b, "????", target.key, target.formControl?.value);
|
|
809
815
|
const results = await factory(target, this.injector) || [];
|
|
810
816
|
return this.fixSelectOptions(target, results);
|
|
811
817
|
})));
|
|
@@ -1206,6 +1212,12 @@ class DynamicFormSchemaService {
|
|
|
1206
1212
|
return !field ? [] : options.customize(field, property, schema);
|
|
1207
1213
|
}
|
|
1208
1214
|
async getFormFieldForProp(property, options, parent) {
|
|
1215
|
+
// First check property references, because a dynamic schema can be a type of object which we use for editor
|
|
1216
|
+
const refs = await this.openApi.getReferences(property, options.schema);
|
|
1217
|
+
if (refs.length > 0) {
|
|
1218
|
+
return this.getFormGroupConfig(property, options, parent);
|
|
1219
|
+
}
|
|
1220
|
+
// Then check the property type
|
|
1209
1221
|
switch (property.type) {
|
|
1210
1222
|
case "object":
|
|
1211
1223
|
return this.getFormEditorConfig(property, options, parent);
|
|
@@ -1233,10 +1245,6 @@ class DynamicFormSchemaService {
|
|
|
1233
1245
|
if (property.format == "date" || property.format == "date-time") {
|
|
1234
1246
|
return this.getFormDatepickerConfig(property, options, parent);
|
|
1235
1247
|
}
|
|
1236
|
-
const refs = await this.openApi.getReferences(property, options.schema);
|
|
1237
|
-
if (refs.length > 0) {
|
|
1238
|
-
return this.getFormGroupConfig(property, options, parent);
|
|
1239
|
-
}
|
|
1240
1248
|
if (this.checkIsEditorProperty(property)) {
|
|
1241
1249
|
return this.getFormEditorConfig(property, options, parent);
|
|
1242
1250
|
}
|
|
@@ -1329,7 +1337,7 @@ class DynamicFormSchemaService {
|
|
|
1329
1337
|
break;
|
|
1330
1338
|
}
|
|
1331
1339
|
const sub = property.type == "array" ? property.items || property : property;
|
|
1332
|
-
|
|
1340
|
+
return this.builder.createFormInput(property.id, {
|
|
1333
1341
|
...this.getFormFieldData(property, options),
|
|
1334
1342
|
type,
|
|
1335
1343
|
autocomplete: property.autocomplete,
|
|
@@ -1343,7 +1351,6 @@ class DynamicFormSchemaService {
|
|
|
1343
1351
|
indeterminate: property.indeterminate,
|
|
1344
1352
|
suffix: property.suffix
|
|
1345
1353
|
}, parent, options);
|
|
1346
|
-
return input;
|
|
1347
1354
|
}
|
|
1348
1355
|
getFormTextareaConfig(property, options, parent) {
|
|
1349
1356
|
return this.builder.createFormInput(property.id, {
|
|
@@ -1529,6 +1536,9 @@ class DynamicFormSchemaService {
|
|
|
1529
1536
|
if (Array.isArray(property.enum)) {
|
|
1530
1537
|
validators.enum = enumValidation(property.enum);
|
|
1531
1538
|
}
|
|
1539
|
+
if ("equals" in property) {
|
|
1540
|
+
validators.equals = equalsValidation(property.equals);
|
|
1541
|
+
}
|
|
1532
1542
|
// if (isString(property.pattern) && property.pattern.length) {
|
|
1533
1543
|
// validators.pattern = property.pattern;
|
|
1534
1544
|
// }
|
|
@@ -1556,6 +1566,9 @@ class DynamicFormSchemaService {
|
|
|
1556
1566
|
if (Array.isArray(items.enum)) {
|
|
1557
1567
|
validators.enum = enumValidation(items.enum);
|
|
1558
1568
|
}
|
|
1569
|
+
if ("equals" in items) {
|
|
1570
|
+
validators.equals = equalsValidation(items.equals);
|
|
1571
|
+
}
|
|
1559
1572
|
}
|
|
1560
1573
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormSchemaService, deps: [{ token: i2.OpenApiService }, { token: i0.Injector }, { token: DynamicFormBuilderService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1561
1574
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormSchemaService }); }
|
|
@@ -2498,5 +2511,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImpo
|
|
|
2498
2511
|
* Generated bundle index. Do not edit.
|
|
2499
2512
|
*/
|
|
2500
2513
|
|
|
2501
|
-
export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormEditorComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_TYPES, 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, enumValidation, 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 };
|
|
2514
|
+
export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormEditorComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_TYPES, 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, enumValidation, equalsValidation, 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 };
|
|
2502
2515
|
//# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map
|