2017-12-20 17:46:52 +01:00
|
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { FieldGroup } from 'app/models/DataSetProfile/FieldGroup';
|
2018-01-02 17:29:27 +01:00
|
|
|
|
import { FieldSet } from 'app/models/DataSetProfile/FieldSet';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
import { FormArray } from '@angular/forms/src/model';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { Field } from 'app/models/DataSetProfile/Field';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'groupfield-form',
|
|
|
|
|
templateUrl: './groupfield-form.component.html',
|
|
|
|
|
styleUrls: []
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class GroupFieldFormComponent {
|
|
|
|
|
@Input() form: FormGroup;
|
|
|
|
|
@Input() dataModel: FieldGroup;
|
2017-12-07 14:57:20 +01:00
|
|
|
|
@Input() indexPath: string;
|
|
|
|
|
|
2017-11-27 14:35:00 +01:00
|
|
|
|
constructor(){}
|
|
|
|
|
|
2017-12-13 10:26:02 +01:00
|
|
|
|
ngOnInit(){
|
2017-11-29 17:51:28 +01:00
|
|
|
|
//this.addNewField();
|
2017-11-27 14:35:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 15:00:37 +01:00
|
|
|
|
addNewFieldSet(){
|
2018-01-02 17:29:27 +01:00
|
|
|
|
let compositeField: FieldSet = new FieldSet();
|
2017-12-01 15:00:37 +01:00
|
|
|
|
|
|
|
|
|
let field: Field = new Field(); //create field at the same time
|
|
|
|
|
compositeField.fields.push(field);
|
|
|
|
|
//(<FormArray>this.form.get("compositeFields").get("fields")).push(field.buildForm());
|
|
|
|
|
|
|
|
|
|
|
2017-11-27 14:35:00 +01:00
|
|
|
|
this.dataModel.compositeFields.push(compositeField);
|
|
|
|
|
(<FormArray>this.form.get("compositeFields")).push(compositeField.buildForm());
|
2017-12-01 15:00:37 +01:00
|
|
|
|
|
2017-11-27 14:35:00 +01:00
|
|
|
|
}
|
2017-11-29 17:51:28 +01:00
|
|
|
|
|
|
|
|
|
DeleteFieldSet(index){
|
2017-12-05 12:02:03 +01:00
|
|
|
|
this.dataModel.compositeFields.splice(index, 1);
|
2017-11-29 17:51:28 +01:00
|
|
|
|
(<FormArray>this.form.get("compositeFields")).removeAt(index);
|
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
}
|