Skip to content
Snippets Groups Projects
Commit 695911ad authored by rhenck's avatar rhenck
Browse files

Update form element value on init

parent 0dc3a6e8
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import { pairwise, startWith, takeUntil } from 'rxjs/operators'; ...@@ -9,6 +9,7 @@ import { pairwise, startWith, takeUntil } from 'rxjs/operators';
import { FormService } from './form.service'; import { FormService } from './form.service';
import { ValueChangeElement } from './form'; import { ValueChangeElement } from './form';
import { ElementComponent } from './element-component.directive'; import { ElementComponent } from './element-component.directive';
import { InputUIElement } from './unit';
@Directive() @Directive()
export abstract class FormElementComponent extends ElementComponent implements OnInit, OnDestroy { export abstract class FormElementComponent extends ElementComponent implements OnInit, OnDestroy {
...@@ -29,6 +30,7 @@ export abstract class FormElementComponent extends ElementComponent implements O ...@@ -29,6 +30,7 @@ export abstract class FormElementComponent extends ElementComponent implements O
formGroup: this.parentForm formGroup: this.parentForm
}); });
this.elementFormControl = this.formControl; this.elementFormControl = this.formControl;
this.updateFormValue((this.elementModel as InputUIElement).value);
this.elementFormControl.valueChanges this.elementFormControl.valueChanges
.pipe( .pipe(
startWith(this.elementModel.value), startWith(this.elementModel.value),
...@@ -49,7 +51,7 @@ export abstract class FormElementComponent extends ElementComponent implements O ...@@ -49,7 +51,7 @@ export abstract class FormElementComponent extends ElementComponent implements O
new FormControl({}); new FormControl({});
} }
updateFormValue(newValue: string | number | boolean): void { updateFormValue(newValue: string | number | boolean | undefined): void {
this.elementFormControl?.setValue(newValue, { emitEvent: false }); this.elementFormControl?.setValue(newValue, { emitEvent: false });
} }
......
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