Skip to content
Snippets Groups Projects
Commit 24eae0d4 authored by jojohoch's avatar jojohoch
Browse files

[player] Set initial form and validator value for compound elements

parent 2daf595f
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ export abstract class FormElementComponent extends ElementComponent implements O ...@@ -21,7 +21,7 @@ export abstract class FormElementComponent extends ElementComponent implements O
ngOnInit(): void { ngOnInit(): void {
this.elementFormControl = this.formControl; this.elementFormControl = this.formControl;
this.elementFormControl?.setValue((this.elementModel as InputElement).value, { emitEvent: false }); this.elementFormControl?.setValue((this.elementModel as InputElement).value, { emitEvent: false });
this.setValidators.emit(this.validators); this.setFormControlValidator();
this.elementFormControl.valueChanges this.elementFormControl.valueChanges
.pipe( .pipe(
startWith((this.elementModel as InputElement).value), startWith((this.elementModel as InputElement).value),
...@@ -52,6 +52,10 @@ export abstract class FormElementComponent extends ElementComponent implements O ...@@ -52,6 +52,10 @@ export abstract class FormElementComponent extends ElementComponent implements O
this.elementFormControl.setValue(value); this.elementFormControl.setValue(value);
} }
setFormControlValidator(): void {
this.setValidators.emit(this.validators);
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.ngUnsubscribe.next(); this.ngUnsubscribe.next();
this.ngUnsubscribe.complete(); this.ngUnsubscribe.complete();
......
...@@ -119,7 +119,7 @@ export class ElementContainerComponent implements OnInit { ...@@ -119,7 +119,7 @@ export class ElementContainerComponent implements OnInit {
const elementForm = this.formBuilder.group({}); const elementForm = this.formBuilder.group({});
elementComponent.parentForm = elementForm; elementComponent.parentForm = elementForm;
const compoundChildren = elementComponent.getFormElementModelChildren(); const compoundChildren = elementComponent.getFormElementModelChildren();
this.subscribeCompoundChildren(elementComponent, compoundChildren); this.subscribeCompoundChildren(elementComponent, compoundChildren, elementForm);
this.registerFormGroup(elementForm); this.registerFormGroup(elementForm);
compoundChildren.forEach((element: InputElement) => { compoundChildren.forEach((element: InputElement) => {
this.formService.registerFormControl({ this.formService.registerFormControl({
...@@ -144,7 +144,7 @@ export class ElementContainerComponent implements OnInit { ...@@ -144,7 +144,7 @@ export class ElementContainerComponent implements OnInit {
} }
private subscribeCompoundChildren( private subscribeCompoundChildren(
elementComponent: CompoundElementComponent, compoundChildren: InputElement[] elementComponent: CompoundElementComponent, compoundChildren: InputElement[], elementForm: FormGroup
): void { ): void {
if (elementComponent.childrenAdded) { if (elementComponent.childrenAdded) {
elementComponent.childrenAdded elementComponent.childrenAdded
...@@ -168,7 +168,9 @@ export class ElementContainerComponent implements OnInit { ...@@ -168,7 +168,9 @@ export class ElementContainerComponent implements OnInit {
); );
const formChild = (child as FormElementComponent); const formChild = (child as FormElementComponent);
if (formChild) { if (formChild) {
this.subscribeSetValidators(formChild, elementForm);
formChild.setFormValue(child.elementModel.value); formChild.setFormValue(child.elementModel.value);
formChild.setFormControlValidator();
} }
}); });
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
...@@ -263,7 +265,7 @@ export class ElementContainerComponent implements OnInit { ...@@ -263,7 +265,7 @@ export class ElementContainerComponent implements OnInit {
.pipe(takeUntil(this.ngUnsubscribe)) .pipe(takeUntil(this.ngUnsubscribe))
.subscribe((validators: ValidatorFn[]) => { .subscribe((validators: ValidatorFn[]) => {
this.formService.setValidators({ this.formService.setValidators({
id: this.elementModel.id, id: elementComponent.elementModel.id,
validators: validators, validators: validators,
formGroup: elementForm formGroup: elementForm
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment