|
@@ -48,7 +48,7 @@ export class DynaformComponent implements OnInit {
|
|
|
template?: TemplateRef<any>;
|
|
|
|
|
|
@Input()
|
|
|
- debug = false;
|
|
|
+ debug = true;
|
|
|
|
|
|
@Output()
|
|
|
call: EventEmitter<string> = new EventEmitter<string>();
|
|
@@ -58,6 +58,10 @@ export class DynaformComponent implements OnInit {
|
|
|
dynaFormRows: string[];
|
|
|
path: string[];
|
|
|
|
|
|
+
|
|
|
+ conRed = 'color: white; background-color: maroon; font-weight: bold;';
|
|
|
+ conGreen = 'color: white; background-color: green; font-weight: bold;';
|
|
|
+
|
|
|
constructor(
|
|
|
@Optional() private cc: ControlContainer,
|
|
|
) {}
|
|
@@ -65,16 +69,22 @@ export class DynaformComponent implements OnInit {
|
|
|
ngOnInit() {
|
|
|
|
|
|
if (!this.formGroup && this.formGroupName) {
|
|
|
- this.formGroup = <FormGroup>this.cc.control;
|
|
|
+ this.formGroup = <FormGroup>this.cc.control;
|
|
|
}
|
|
|
if (!this.formGroup) {
|
|
|
throw new Error('Dynaform Component initialised without [formGroup] or formGroupName');
|
|
|
}
|
|
|
+ if (typeof this.formMetaData !== 'object') {
|
|
|
+ throw new Error('Dynaform: [meta] should be an object');
|
|
|
+ }
|
|
|
this.controlNames = Object.keys(this.formGroup.controls);
|
|
|
this.path = this.getFormGroupPath();
|
|
|
+ if (this.debug && this.path.length < 2) {
|
|
|
+ this.displayDebuggingInConsole();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
const path = [...this.path];
|
|
|
const metaDataKeysExpected = this.controlNames.join(',');
|
|
|
while (path.length && metaDataKeysExpected !== this.getContolKeysCSVFromMetadata(this.formMetaData)) {
|
|
@@ -84,8 +94,6 @@ export class DynaformComponent implements OnInit {
|
|
|
this.dynaFormRows = Object.keys(this.formMetaData);
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
const metaDataKeysFound = this.getContolKeysCSVFromMetadata(this.formMetaData);
|
|
|
if (metaDataKeysFound !== metaDataKeysExpected) {
|
|
|
throw new Error(`
|
|
@@ -148,7 +156,7 @@ export class DynaformComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
private getContolKeysCSVFromMetadata(metadata): string {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -158,4 +166,11 @@ export class DynaformComponent implements OnInit {
|
|
|
.join(',');
|
|
|
}
|
|
|
|
|
|
+ private displayDebuggingInConsole(): void {
|
|
|
+ console.log('%c *** MetaData *** ', this.conGreen);
|
|
|
+ console.dir(this.formMetaData);
|
|
|
+ console.log('%c *** FormGroup *** ', this.conGreen);
|
|
|
+ console.dir(this.formGroup);
|
|
|
+ }
|
|
|
+
|
|
|
}
|