Skip to content

Commit

Permalink
fix: new assets on entry create + removed hacks from input.component
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Aug 9, 2018
1 parent de4b324 commit 04fffbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Expand Up @@ -120,7 +120,7 @@ export class AssetSelectComponent extends SelectComponent<DMAssetResource | Publ
console.error('ALARM: asset picker hat neues asset aber assetGroupID "' + this.assetGroupID + '". Bitte füge im model die assetGroupID "' + this.getAssetGroupID() + '" als validation des feldes hinzu');
}
config = this.dmAssetConfig;
this.assetGroupID = this.getAssetGroupID();
this.assetGroupID = this.assetGroupID || this.getAssetGroupID();
} else if (this.containsOldAssets() || this.assetGroupID === 'legacyAsset') {
// legacy assets
if (this.assetGroupID && this.assetGroupID !== 'legacyAsset') {
Expand Down
20 changes: 13 additions & 7 deletions packages/ui/src/io/input/input.component.ts
@@ -1,9 +1,6 @@
import { Component, EventEmitter, forwardRef, Input, OnChanges, Output, Type } from '@angular/core';
import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, AbstractControl } from '@angular/forms';
import { FieldConfigProperty } from '../../../../core';
import { Field } from '../../../../core/src/field/field';
import { Form } from '../../../../core/src/form/form';
import { Item } from '../../../../core/src/item/item';
import { FieldConfigProperty, Field, Form, Item } from '@ec.components/core';
import { DefaultInputComponent } from '../../form/default-input/default-input.component';
import { DynamicSlotComponent } from '../dynamic-slot/dynamic-slot.component';

Expand Down Expand Up @@ -40,7 +37,7 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue
@Input() component: Type<any>;
/** 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) {
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand All @@ -94,6 +99,7 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue
/** Registers change callback */
registerOnChange(fn) {
this.propagateChange = fn;
this.connectControl();
}

registerOnTouched() {
Expand Down

0 comments on commit 04fffbd

Please sign in to comment.