|
@@ -58,24 +58,6 @@ export class DynaformComponent implements OnInit {
|
|
) {}
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
-
|
|
|
|
- // Get the full path in the tree (used to match metadata)
|
|
|
|
- let parents = [];
|
|
|
|
- if (this.formGroup) {
|
|
|
|
- // formGroup supplied directly, so reconstruct current FormGroup's full path
|
|
|
|
- let fg = this.formGroup;
|
|
|
|
- while (fg.parent) {
|
|
|
|
- // Find the identity (i.e. object key) of the parent FormGroup that IS FormGroup 'fg'
|
|
|
|
- const fgIdentity = Object.entries(fg.parent.controls).filter(([key, candidate]) => candidate === fg);
|
|
|
|
- parents.push(fgIdentity[0][0]);
|
|
|
|
- fg = <FormGroup>fg.parent;
|
|
|
|
- }
|
|
|
|
- } else if (this.formGroupName) {
|
|
|
|
- // formGroupName supplied, so get the full path from the ControlContainer
|
|
|
|
- parents = this.cc.path.reverse();
|
|
|
|
- }
|
|
|
|
- const path = parents;
|
|
|
|
-
|
|
|
|
// Get the formGroup from the formGroupName if necessary
|
|
// Get the formGroup from the formGroupName if necessary
|
|
if (!this.formGroup && this.formGroupName) {
|
|
if (!this.formGroup && this.formGroupName) {
|
|
this.formGroup = <FormGroup>this.cc.control; // Get theFormGroup from the ControlContainer
|
|
this.formGroup = <FormGroup>this.cc.control; // Get theFormGroup from the ControlContainer
|
|
@@ -87,6 +69,7 @@ export class DynaformComponent implements OnInit {
|
|
|
|
|
|
// If we're given a formGroupName or nested FormFroup, and the form's full (or partial but fuller) metadata tree,
|
|
// If we're given a formGroupName or nested FormFroup, and the form's full (or partial but fuller) metadata tree,
|
|
// drill down to find the corresponding FormGroup's metadata
|
|
// drill down to find the corresponding FormGroup's metadata
|
|
|
|
+ const path = this.getFormGroupPath();
|
|
const metaDataKeysExpected = this.controlNames.join(',');
|
|
const metaDataKeysExpected = this.controlNames.join(',');
|
|
while (path.length && metaDataKeysExpected !== Object.keys(this.formMetaData).join(',')) {
|
|
while (path.length && metaDataKeysExpected !== Object.keys(this.formMetaData).join(',')) {
|
|
const branch = path.pop();
|
|
const branch = path.pop();
|
|
@@ -104,6 +87,25 @@ export class DynaformComponent implements OnInit {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getFormGroupPath(): string[] {
|
|
|
|
+ // Get the full path of the FormGroup (used to match and validate metadata)
|
|
|
|
+ let path = [];
|
|
|
|
+ if (!this.formGroup && this.formGroupName) {
|
|
|
|
+ // formGroupName supplied, so get the full path from the ControlContainer
|
|
|
|
+ path = this.cc.path.reverse();
|
|
|
|
+ } else {
|
|
|
|
+ // formGroup supplied directly, so reconstruct current FormGroup's full path
|
|
|
|
+ let fg = this.formGroup;
|
|
|
|
+ while (fg.parent) {
|
|
|
|
+ // Find the identity of 'fg' in the parent FormGroup's controls
|
|
|
|
+ const fgIdentity = Object.entries(fg.parent.controls).filter(([key, candidate]) => candidate === fg).pop();
|
|
|
|
+ path.push(fgIdentity[0]);
|
|
|
|
+ fg = <FormGroup>fg.parent;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return path;
|
|
|
|
+ }
|
|
|
|
+
|
|
getTemplateContext(controlName: string): DynarowContext {
|
|
getTemplateContext(controlName: string): DynarowContext {
|
|
return {
|
|
return {
|
|
control: this.formGroup.get(controlName),
|
|
control: this.formGroup.get(controlName),
|