@stemy/ngx-dynamic-form 19.9.19 → 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((control, field) => {
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);
@@ -1150,10 +1153,6 @@ class DynamicFormSchemaService {
1150
1153
  return !field ? [] : options.customize(field, property, schema);
1151
1154
  }
1152
1155
  async getFormFieldForProp(property, options, parent) {
1153
- const $enum = property.items?.enum || property.enum;
1154
- if (Array.isArray($enum) || ObjectUtils.isStringWithValue(property.optionsPath) || ObjectUtils.isStringWithValue(property.endpoint)) {
1155
- return this.getFormSelectConfig($enum, property, options, parent);
1156
- }
1157
1156
  switch (property.type) {
1158
1157
  // case "object":
1159
1158
  // return this.getFormEditorConfig(property, options, parent);
@@ -1165,6 +1164,10 @@ class DynamicFormSchemaService {
1165
1164
  case "array":
1166
1165
  return this.getFormArrayConfig(property, options, parent);
1167
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
+ }
1168
1171
  // if (this.checkIsEditorProperty(property)) {
1169
1172
  // return this.getFormEditorConfig(property, options, parent);
1170
1173
  // }
@@ -1399,7 +1402,7 @@ class DynamicFormSchemaService {
1399
1402
  item = ObjectUtils.isObject(item) ? item : { id: item };
1400
1403
  return {
1401
1404
  ...item,
1402
- value: item.id || item._id,
1405
+ value: item[property.idField] || item.id || item._id,
1403
1406
  label: item[property.labelField] || item.label || item.id || item._id
1404
1407
  };
1405
1408
  }));
@@ -1472,6 +1475,12 @@ class DynamicFormSchemaService {
1472
1475
  if (!isNaN(property.maximum)) {
1473
1476
  validators.max = maxValueValidation();
1474
1477
  }
1478
+ if (!isNaN(property.maximum)) {
1479
+ validators.max = maxValueValidation();
1480
+ }
1481
+ if (Array.isArray(property.enum)) {
1482
+ validators.enum = enumValidation(property.enum);
1483
+ }
1475
1484
  // if (isString(property.pattern) && property.pattern.length) {
1476
1485
  // validators.pattern = property.pattern;
1477
1486
  // }
@@ -1496,6 +1505,9 @@ class DynamicFormSchemaService {
1496
1505
  if (!isNaN(items.maximum)) {
1497
1506
  validators.itemsMaxValue = maxValueValidation();
1498
1507
  }
1508
+ if (Array.isArray(items.enum)) {
1509
+ validators.enum = enumValidation(items.enum);
1510
+ }
1499
1511
  }
1500
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 });
1501
1513
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormSchemaService });
@@ -2438,5 +2450,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
2438
2450
  * Generated bundle index. Do not edit.
2439
2451
  */
2440
2452
 
2441
- 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 };
2442
2454
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map