@stemy/ngx-dynamic-form 19.9.18 → 19.9.21
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.
|
@@ -378,9 +378,7 @@ function jsonValidation() {
|
|
|
378
378
|
}, "json");
|
|
379
379
|
}
|
|
380
380
|
function requiredValidation() {
|
|
381
|
-
return withName(
|
|
382
|
-
if (field.props?.type === "checkbox")
|
|
383
|
-
return control.value === true;
|
|
381
|
+
return withName(control => {
|
|
384
382
|
return ObjectUtils.isString(control.value) ? control.value.length > 0 : ObjectUtils.isDefined(control.value);
|
|
385
383
|
}, "required");
|
|
386
384
|
}
|
|
@@ -446,6 +444,11 @@ function maxValueValidation() {
|
|
|
446
444
|
return v == null || v <= max;
|
|
447
445
|
}, "maxValue");
|
|
448
446
|
}
|
|
447
|
+
function enumValidation($enum) {
|
|
448
|
+
return validateEach(v => {
|
|
449
|
+
return $enum.includes(v);
|
|
450
|
+
}, "enum");
|
|
451
|
+
}
|
|
449
452
|
function setFieldMinDate(field, min) {
|
|
450
453
|
setFieldDefault(field, min);
|
|
451
454
|
setFieldProp(field, "min", min);
|
|
@@ -769,11 +772,13 @@ class DynamicFormBuilderService {
|
|
|
769
772
|
}
|
|
770
773
|
createFormSelect(key, data, parent, options) {
|
|
771
774
|
data = data || {};
|
|
775
|
+
const multiple = data.multiple === true;
|
|
776
|
+
data.defaultValue = data.defaultValue ?? (multiple ? [] : null);
|
|
772
777
|
const type = `${data.type || "select"}`;
|
|
773
778
|
const fieldType = type === "radio" ? type : (data.strict === false ? "chips" : "select");
|
|
774
779
|
const field = this.createFormField(key, fieldType, data, {
|
|
775
780
|
type,
|
|
776
|
-
multiple
|
|
781
|
+
multiple,
|
|
777
782
|
strict: data.strict !== false,
|
|
778
783
|
allowEmpty: data.allowEmpty === true,
|
|
779
784
|
groupBy: data.groupBy,
|
|
@@ -933,8 +938,15 @@ class DynamicFormBuilderService {
|
|
|
933
938
|
}));
|
|
934
939
|
const control = field.formControl;
|
|
935
940
|
const multiple = field.props.multiple;
|
|
936
|
-
|
|
937
|
-
|
|
941
|
+
if (multiple) {
|
|
942
|
+
// Handle if current control value is not an array
|
|
943
|
+
const value = Array.isArray(control.value)
|
|
944
|
+
? control.value
|
|
945
|
+
: String(control.value || "").split(",");
|
|
946
|
+
control.setValue(value);
|
|
947
|
+
return options;
|
|
948
|
+
}
|
|
949
|
+
if (options.length === 0 || options.findIndex(o => o.value === control.value) >= 0)
|
|
938
950
|
return options;
|
|
939
951
|
control.setValue(field.defaultValue);
|
|
940
952
|
return options;
|
|
@@ -1141,10 +1153,6 @@ class DynamicFormSchemaService {
|
|
|
1141
1153
|
return !field ? [] : options.customize(field, property, schema);
|
|
1142
1154
|
}
|
|
1143
1155
|
async getFormFieldForProp(property, options, parent) {
|
|
1144
|
-
const $enum = property.items?.enum || property.enum;
|
|
1145
|
-
if (Array.isArray($enum) || ObjectUtils.isStringWithValue(property.optionsPath) || ObjectUtils.isStringWithValue(property.endpoint)) {
|
|
1146
|
-
return this.getFormSelectConfig($enum, property, options, parent);
|
|
1147
|
-
}
|
|
1148
1156
|
switch (property.type) {
|
|
1149
1157
|
// case "object":
|
|
1150
1158
|
// return this.getFormEditorConfig(property, options, parent);
|
|
@@ -1156,6 +1164,10 @@ class DynamicFormSchemaService {
|
|
|
1156
1164
|
case "array":
|
|
1157
1165
|
return this.getFormArrayConfig(property, options, parent);
|
|
1158
1166
|
}
|
|
1167
|
+
const $enum = property.items?.enum || property.enum;
|
|
1168
|
+
if (Array.isArray($enum) || ObjectUtils.isStringWithValue(property.optionsPath) || ObjectUtils.isStringWithValue(property.endpoint)) {
|
|
1169
|
+
return this.getFormSelectConfig($enum, property, options, parent);
|
|
1170
|
+
}
|
|
1159
1171
|
// if (this.checkIsEditorProperty(property)) {
|
|
1160
1172
|
// return this.getFormEditorConfig(property, options, parent);
|
|
1161
1173
|
// }
|
|
@@ -1378,8 +1390,9 @@ class DynamicFormSchemaService {
|
|
|
1378
1390
|
const endpoint = entries.reduce((res, [key, control]) => {
|
|
1379
1391
|
return this.replaceOptionsEndpoint(res, key, control.value);
|
|
1380
1392
|
}, `${property.endpoint}`);
|
|
1393
|
+
const cache = property.cache ?? new Date(Date.now() + 20_000);
|
|
1381
1394
|
const data = await this.api.list(endpoint, this.api.makeListParams(1, -1), {
|
|
1382
|
-
cache: this.api.cached(
|
|
1395
|
+
cache: this.api.cached(cache),
|
|
1383
1396
|
read: String(property.responseProperty || "")
|
|
1384
1397
|
});
|
|
1385
1398
|
const items = ObjectUtils.isArray(data)
|
|
@@ -1389,7 +1402,7 @@ class DynamicFormSchemaService {
|
|
|
1389
1402
|
item = ObjectUtils.isObject(item) ? item : { id: item };
|
|
1390
1403
|
return {
|
|
1391
1404
|
...item,
|
|
1392
|
-
value: item.id || item._id,
|
|
1405
|
+
value: item[property.idField] || item.id || item._id,
|
|
1393
1406
|
label: item[property.labelField] || item.label || item.id || item._id
|
|
1394
1407
|
};
|
|
1395
1408
|
}));
|
|
@@ -1462,6 +1475,12 @@ class DynamicFormSchemaService {
|
|
|
1462
1475
|
if (!isNaN(property.maximum)) {
|
|
1463
1476
|
validators.max = maxValueValidation();
|
|
1464
1477
|
}
|
|
1478
|
+
if (!isNaN(property.maximum)) {
|
|
1479
|
+
validators.max = maxValueValidation();
|
|
1480
|
+
}
|
|
1481
|
+
if (Array.isArray(property.enum)) {
|
|
1482
|
+
validators.enum = enumValidation(property.enum);
|
|
1483
|
+
}
|
|
1465
1484
|
// if (isString(property.pattern) && property.pattern.length) {
|
|
1466
1485
|
// validators.pattern = property.pattern;
|
|
1467
1486
|
// }
|
|
@@ -1486,6 +1505,9 @@ class DynamicFormSchemaService {
|
|
|
1486
1505
|
if (!isNaN(items.maximum)) {
|
|
1487
1506
|
validators.itemsMaxValue = maxValueValidation();
|
|
1488
1507
|
}
|
|
1508
|
+
if (Array.isArray(items.enum)) {
|
|
1509
|
+
validators.enum = enumValidation(items.enum);
|
|
1510
|
+
}
|
|
1489
1511
|
}
|
|
1490
1512
|
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 });
|
|
1491
1513
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormSchemaService });
|
|
@@ -2428,5 +2450,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
2428
2450
|
* Generated bundle index. Do not edit.
|
|
2429
2451
|
*/
|
|
2430
2452
|
|
|
2431
|
-
export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, 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 };
|
|
2453
|
+
export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, 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, 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 };
|
|
2432
2454
|
//# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map
|