@stemy/ngx-dynamic-form 13.3.11 → 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.
- package/esm2020/ngx-dynamic-form/services/dynamic-form.service.mjs +13 -3
- package/esm2020/ngx-dynamic-form/utils/validation-errors.mjs +13 -18
- package/fesm2015/stemy-ngx-dynamic-form.mjs +30 -27
- package/fesm2015/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/fesm2020/stemy-ngx-dynamic-form.mjs +32 -28
- package/fesm2020/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/ngx-dynamic-form/services/dynamic-form.service.d.ts +2 -0
- package/ngx-dynamic-form/utils/validation-errors.d.ts +4 -4
- package/package.json +1 -1
|
@@ -472,6 +472,27 @@ class FormSelectSubject extends FormSubject {
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
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
|
+
|
|
475
496
|
class DynamicFormService extends DynamicFormService$1 {
|
|
476
497
|
constructor(cs, vs, openApi, injector) {
|
|
477
498
|
super(cs, vs);
|
|
@@ -506,6 +527,14 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
506
527
|
this.showErrorsForGroup(form.group);
|
|
507
528
|
this.detectChanges(form);
|
|
508
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
|
+
}
|
|
509
538
|
patchValueRecursive(value, formModel, formGroup) {
|
|
510
539
|
if (!value)
|
|
511
540
|
return;
|
|
@@ -953,11 +982,12 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
953
982
|
const item = ObjectUtils.isObject(i) ? i : { id: i };
|
|
954
983
|
return {
|
|
955
984
|
...item,
|
|
956
|
-
value: item.id || item._id,
|
|
985
|
+
value: item.id || item._id,
|
|
986
|
+
label: item[property.labelField] || item.label || item.id || item._id
|
|
957
987
|
};
|
|
958
988
|
});
|
|
959
989
|
});
|
|
960
|
-
const options = (await this.api.cache[
|
|
990
|
+
const options = (await this.api.cache[endpoint]).map(t => Object.assign({}, t));
|
|
961
991
|
return this.fixSelectOptions(selectModel, control, options);
|
|
962
992
|
});
|
|
963
993
|
}
|
|
@@ -1061,32 +1091,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
|
|
|
1061
1091
|
args: [Injector]
|
|
1062
1092
|
}] }]; } });
|
|
1063
1093
|
|
|
1064
|
-
function getFormValidationErrors(controls) {
|
|
1065
|
-
let errors = [];
|
|
1066
|
-
Object.keys(controls).forEach(key => {
|
|
1067
|
-
const control = controls[key];
|
|
1068
|
-
if (control instanceof FormGroup) {
|
|
1069
|
-
errors = errors.concat(getFormValidationErrors(control.controls));
|
|
1070
|
-
}
|
|
1071
|
-
if (control instanceof FormArray) {
|
|
1072
|
-
control.controls.forEach((control) => {
|
|
1073
|
-
errors = errors.concat(getFormValidationErrors(control.controls));
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
if (control.errors !== null) {
|
|
1077
|
-
Object.keys(control.errors).forEach(keyError => {
|
|
1078
|
-
errors.push({
|
|
1079
|
-
control,
|
|
1080
|
-
control_name: key,
|
|
1081
|
-
error_name: keyError,
|
|
1082
|
-
error_value: control.errors[keyError]
|
|
1083
|
-
});
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
});
|
|
1087
|
-
return errors;
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
1094
|
class AsyncSubmitDirective {
|
|
1091
1095
|
constructor(toaster, cdr, elem, renderer) {
|
|
1092
1096
|
this.toaster = toaster;
|