|
@@ -1,7 +1,8 @@
|
|
|
import { Component, Input, Output, EventEmitter, TemplateRef, Optional, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
|
|
-import { FormControl, FormGroup, FormArray, FormGroupName, AbstractControl, ControlContainer } from '@angular/forms';
|
|
|
+import { FormBuilder, FormControl, FormGroup, FormArray, FormGroupName, AbstractControl, ControlContainer } from '@angular/forms';
|
|
|
import { SuperForm } from 'angular-super-validator';
|
|
|
-import { unwrapResolvedMetadata } from '@angular/compiler';
|
|
|
+import { buildFormGroupFunctionFactory } from './services/_formdata-utils';
|
|
|
+import { cloneDeep } from 'lodash/fp';
|
|
|
|
|
|
export interface DynarowContext {
|
|
|
control: AbstractControl;
|
|
@@ -180,10 +181,19 @@ export class DynaformComponent implements OnInit {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // Maybe move the next two funtions to _formdata-utils.ts ?
|
|
|
addRCMember(repeatingContainerName: string): void {
|
|
|
+ // (1) Add metadata for new container member
|
|
|
const rcMeta = this.formMetaData[repeatingContainerName];
|
|
|
- rcMeta.meta.push(rcMeta.__defaultContainer);
|
|
|
- console.log(rcMeta);
|
|
|
+ const containerTemplate = cloneDeep(rcMeta.__containerTemplate);
|
|
|
+ const i = this.formMetaData[repeatingContainerName].meta.length;
|
|
|
+ containerTemplate.name = `group${i+1}`;
|
|
|
+ rcMeta.meta.push(containerTemplate);
|
|
|
+
|
|
|
+ // (2) Add FormGroup for new container member
|
|
|
+ const buildFormGroup = buildFormGroupFunctionFactory(new FormBuilder());
|
|
|
+ const newFormGroup = buildFormGroup(containerTemplate.meta);
|
|
|
+ (this.formGroup.get(repeatingContainerName) as FormArray).push(newFormGroup);
|
|
|
}
|
|
|
|
|
|
deleteRCMember(repeatingContainerName: string, index: number): void {
|