@stemy/ngx-dynamic-form 13.3.10 → 13.3.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.
@@ -192,6 +192,7 @@ class DynamicSelectModel extends DynamicSelectModel$1 {
192
192
  this.groupBy = config.groupBy || null;
193
193
  this.inline = config.inline || false;
194
194
  this.getClasses = ObjectUtils.isFunction(config.getClasses) ? config.getClasses : (() => "");
195
+ this.allowEmpty = config.allowEmpty || false;
195
196
  this.mOptions = this.mOptions || [];
196
197
  }
197
198
  updateOptions() {
@@ -463,7 +464,7 @@ class FormSelectSubject extends FormSubject {
463
464
  else {
464
465
  const option = options.find(t => t.value == currentVal);
465
466
  if (!option) {
466
- control.setValue(options[0]?.value ?? null, { onlySelf: true, emitEvent: false });
467
+ control.setValue(controlModel.allowEmpty ? null : options[0]?.value ?? null, { onlySelf: true, emitEvent: false });
467
468
  }
468
469
  }
469
470
  this.next(options);
@@ -471,6 +472,27 @@ class FormSelectSubject extends FormSubject {
471
472
  }
472
473
  }
473
474
 
475
+ function getFormValidationErrors(controls, parentPath = "") {
476
+ const errors = [];
477
+ Object.entries(controls).forEach(([name, control], ix) => {
478
+ const path = !parentPath ? name : `${parentPath}.${name}`;
479
+ if (control instanceof FormGroup) {
480
+ getFormValidationErrors(control.controls, path).forEach(error => errors.push(error));
481
+ return;
482
+ }
483
+ if (control instanceof FormArray) {
484
+ control.controls.forEach((control, ix) => {
485
+ getFormValidationErrors(control.controls, `${path}.${ix}`).forEach(error => errors.push(error));
486
+ });
487
+ return;
488
+ }
489
+ Object.entries(control.errors || {}).forEach(([errorKey, errorValue]) => {
490
+ errors.push({ control, path, errorKey, errorValue });
491
+ });
492
+ });
493
+ return errors;
494
+ }
495
+
474
496
  class DynamicFormService extends DynamicFormService$1 {
475
497
  constructor(cs, vs, openApi, injector) {
476
498
  super(cs, vs);
@@ -505,6 +527,14 @@ class DynamicFormService extends DynamicFormService$1 {
505
527
  this.showErrorsForGroup(form.group);
506
528
  this.detectChanges(form);
507
529
  }
530
+ getErrors(form) {
531
+ this.showErrors(form);
532
+ return new Promise(resolve => {
533
+ setTimeout(() => {
534
+ resolve(getFormValidationErrors(form.group.controls, ""));
535
+ }, 500);
536
+ });
537
+ }
508
538
  patchValueRecursive(value, formModel, formGroup) {
509
539
  if (!value)
510
540
  return;
@@ -952,11 +982,12 @@ class DynamicFormService extends DynamicFormService$1 {
952
982
  const item = ObjectUtils.isObject(i) ? i : { id: i };
953
983
  return {
954
984
  ...item,
955
- value: item.id || item._id, label: item[property.labelField] || item.label || item.id || item._id
985
+ value: item.id || item._id,
986
+ label: item[property.labelField] || item.label || item.id || item._id
956
987
  };
957
988
  });
958
989
  });
959
- const options = (await this.api.cache[property.endpoint]).map(t => Object.assign({}, t));
990
+ const options = (await this.api.cache[endpoint]).map(t => Object.assign({}, t));
960
991
  return this.fixSelectOptions(selectModel, control, options);
961
992
  });
962
993
  }
@@ -965,7 +996,8 @@ class DynamicFormService extends DynamicFormService$1 {
965
996
  options: this.getFormSelectOptions(property, schema),
966
997
  multiple: property.type == "array",
967
998
  groupBy: property.groupBy,
968
- inline: property.inline
999
+ inline: property.inline,
1000
+ allowEmpty: property.allowEmpty,
969
1001
  });
970
1002
  }
971
1003
  getFormUploadConfig(property, schema) {
@@ -1059,32 +1091,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1059
1091
  args: [Injector]
1060
1092
  }] }]; } });
1061
1093
 
1062
- function getFormValidationErrors(controls) {
1063
- let errors = [];
1064
- Object.keys(controls).forEach(key => {
1065
- const control = controls[key];
1066
- if (control instanceof FormGroup) {
1067
- errors = errors.concat(getFormValidationErrors(control.controls));
1068
- }
1069
- if (control instanceof FormArray) {
1070
- control.controls.forEach((control) => {
1071
- errors = errors.concat(getFormValidationErrors(control.controls));
1072
- });
1073
- }
1074
- if (control.errors !== null) {
1075
- Object.keys(control.errors).forEach(keyError => {
1076
- errors.push({
1077
- control,
1078
- control_name: key,
1079
- error_name: keyError,
1080
- error_value: control.errors[keyError]
1081
- });
1082
- });
1083
- }
1084
- });
1085
- return errors;
1086
- }
1087
-
1088
1094
  class AsyncSubmitDirective {
1089
1095
  constructor(toaster, cdr, elem, renderer) {
1090
1096
  this.toaster = toaster;