Skip to content

Commit b5a578d

Browse files
committed
fix: EDITOR-277 + started COM-237
1 parent 30dfc6c commit b5a578d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

packages/data/src/lib/entry-form/admin-entry-input.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div [ngSwitch]="field.type" *ngIf="group" [formGroup]="group">
22
<ec-input-errors [control]="group.get(field.property)"></ec-input-errors>
33
<div *ngSwitchCase="'account'">
4-
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="field.api"
4+
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="sdk.root | async"
55
relation="dmAccount" [formControl]="group.get(field.property)" [id]="field.id" [solo]="true"></ec-resource-select>
66
</div>
77
<div *ngSwitchCase="'accounts'">
8-
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="field.api"
8+
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="sdk.root | async"
99
relation="dmAccount" [formControl]="group.get(field.property)" [id]="field.id"></ec-resource-select>
1010
</div>
1111
<div *ngSwitchCase="'role'">
12-
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="field.api"
12+
<ec-resource-select [config]="field.nestedCrudConfig" [placeholder]="field.placeholder" [api]="sdk.root | async"
1313
relation="role" [formControl]="group.get(field.property)" [id]="field.id" [solo]="true"></ec-resource-select>
1414
</div>
1515
<div *ngSwitchCase="'resource'">

packages/ui/src/lib/form/form.component.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,24 @@ export class FormComponent<T> implements OnChanges, WithLoader, WithNotification
220220
}
221221
return this.group.value;
222222
}
223+
224+
/** Returns an Error containing all field validator errors as subErrors. */
225+
getErrors(formComponent: FormComponent<T>, touchedOnly = true): Error {
226+
const errs = Object.keys(formComponent.group.controls).reduce((errors, property) => {
227+
const control = formComponent.group.get(property);
228+
if ((touchedOnly && !control.touched) || !control.errors) {
229+
return errors;
230+
}
231+
return errors.concat({ property, errors: control.errors });
232+
}, []);
233+
if (!errs.length) {
234+
return;
235+
}
236+
const error: any = new Error('Validierungsfehler');
237+
error.subErrors = errs.map(({ property, errors }) => {
238+
const label = formComponent.form.getField(property).label || property;
239+
return new Error(label + ': ' + Object.values(errors).join(', '));
240+
});
241+
return error;
242+
}
223243
}

0 commit comments

Comments
 (0)