From 04fffbd71c7632703a0514831fcb8ad9d2ab707e Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 9 Aug 2018 11:25:04 +0200 Subject: [PATCH] fix: new assets on entry create + removed hacks from input.component --- .../asset-select/asset-select.component.ts | 2 +- packages/ui/src/io/input/input.component.ts | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/data/src/files/asset-select/asset-select.component.ts b/packages/data/src/files/asset-select/asset-select.component.ts index 37ed22df7..600c26e15 100644 --- a/packages/data/src/files/asset-select/asset-select.component.ts +++ b/packages/data/src/files/asset-select/asset-select.component.ts @@ -120,7 +120,7 @@ export class AssetSelectComponent extends SelectComponent; /** Holds a reference to the component instance. This is helpful when you want to modify the component after form intialization. * You can access a form's InputComponents via FormComponent#inputs */ - componentInstance: Component + componentInstance: InputComponent ngOnChanges() { if (this.property && this.item instanceof Form) { @@ -66,8 +63,10 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue field: this.field, input: this }; + const componentRef = this.loadComponent(this.component || this.field.input || DefaultInputComponent, data); this.componentInstance = componentRef.instance; + this.connectControl(); if (componentRef.instance.control) { componentRef.instance.control.valueChanges .debounceTime(this.debounce) @@ -81,10 +80,16 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue } } + connectControl() { + if (this.componentInstance.registerOnChange && this.propagateChange) { + this.componentInstance.registerOnChange(this.propagateChange); + } + } + /** writes value to editor on outside model change. */ writeValue(value: any) { - if (this.componentInstance && this.componentInstance['writeValue']) { - this.componentInstance['writeValue'](value); // TODO: this is pretty hacky + if (this.componentInstance.writeValue) { + this.componentInstance.writeValue(value); } } @@ -94,6 +99,7 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue /** Registers change callback */ registerOnChange(fn) { this.propagateChange = fn; + this.connectControl(); } registerOnTouched() {