|
@@ -77,7 +77,7 @@ export class DynaformComponent implements OnInit {
|
|
|
// drill down to find the FormGroup's metadata
|
|
|
const path = [...this.path]; // Clone to avoid mutating this.path
|
|
|
const metaDataKeysExpected = this.controlNames.join(',');
|
|
|
- while (path.length && metaDataKeysExpected !== Object.keys(this.formMetaData).join(',')) {
|
|
|
+ while (path.length && metaDataKeysExpected !== this.getContolKeysCSVFromMetadata(this.formMetaData)) {
|
|
|
const branch = path.pop();
|
|
|
this.formMetaData = this.formMetaData[branch].meta;
|
|
|
}
|
|
@@ -86,15 +86,12 @@ export class DynaformComponent implements OnInit {
|
|
|
// Check we've got a "FormGroup <---> MetaData" match
|
|
|
//
|
|
|
// const metaDataKeys = Object.keys(this.formMetaData).join(','); // OLD VERSION - before we introduced entities like ButtonGroup that don't create FormControls
|
|
|
- const metaDataKeys = Object.entries(this.formMetaData)
|
|
|
- .filter(([key, val]) => !(<StringMap>val).noFormControls)
|
|
|
- .reduce((acc, [key]) => [...acc, key], [])
|
|
|
- .join(',');
|
|
|
- if (metaDataKeys !== metaDataKeysExpected) {
|
|
|
+ const metaDataKeysFound = this.getContolKeysCSVFromMetadata(this.formMetaData);
|
|
|
+ if (metaDataKeysFound !== metaDataKeysExpected) {
|
|
|
throw new Error(`
|
|
|
Dynaform can't match FormGroup's controls with metadata
|
|
|
Expected ${metaDataKeysExpected}
|
|
|
- Got ${metaDataKeys}`
|
|
|
+ Got ${metaDataKeysFound}`
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -119,7 +116,6 @@ export class DynaformComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
getTemplateContext(controlName: string): DynarowContext {
|
|
|
- // console.log(controlName);
|
|
|
return {
|
|
|
control: this.formGroup.get(controlName),
|
|
|
meta: this.formMetaData[controlName]
|
|
@@ -132,7 +128,6 @@ export class DynaformComponent implements OnInit {
|
|
|
|
|
|
getValidationErrors() {
|
|
|
if (!this.formGroup.valid) {
|
|
|
- // const errors = SuperForm.getAllErrors(this.formGroup);
|
|
|
const errorsFlat = SuperForm.getAllErrorsFlat(this.formGroup);
|
|
|
return errorsFlat;
|
|
|
}
|
|
@@ -140,7 +135,19 @@ export class DynaformComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
handle(val) {
|
|
|
+ console.log('Dynaform Component', val);
|
|
|
this.call.emit(val);
|
|
|
}
|
|
|
|
|
|
+ private getContolKeysCSVFromMetadata(metadata): string {
|
|
|
+ // Return CSV of control keys references in nesting-levels metadata,
|
|
|
+ // excluding metadata points that don't create FormControls, FromGroups or FormArrays
|
|
|
+ // (identified by their 'noFormControsl' flag)
|
|
|
+ // e.g. ButtonGroups, HTMLChunks, etc.
|
|
|
+ return Object.entries(metadata)
|
|
|
+ .filter(([key, val]) => !(<StringMap>val).noFormControls)
|
|
|
+ .reduce((acc, [key]) => [...acc, key], [])
|
|
|
+ .join(',');
|
|
|
+ }
|
|
|
+
|
|
|
}
|