2018-05-28 11:50:42 +02:00
|
|
|
import { VisibilityRulesService } from '../../utilities/visibility-rules/visibility-rules.service';
|
2017-11-23 11:40:02 +01:00
|
|
|
import { FieldGroup } from '../../models/FieldGroup';
|
2017-12-06 11:35:50 +01:00
|
|
|
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
2017-12-11 14:47:52 +01:00
|
|
|
import { FormGroup, Validators, FormControl, FormArray } from '@angular/forms';
|
2017-09-14 12:37:36 +02:00
|
|
|
import { NgForm } from '@angular/forms';
|
2017-12-11 14:47:52 +01:00
|
|
|
import { CompositeField } from '../../models/CompositeField';
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'df-group',
|
|
|
|
templateUrl: './dynamic-form-group.component.html',
|
2017-12-06 11:35:50 +01:00
|
|
|
styleUrls: ['./dynamic-form-group.component.css'],
|
|
|
|
encapsulation: ViewEncapsulation.None,
|
2017-09-14 12:37:36 +02:00
|
|
|
})
|
|
|
|
export class DynamicFormGroupComponent implements OnInit {
|
2017-11-23 11:40:02 +01:00
|
|
|
@Input() group: FieldGroup
|
2017-09-14 12:37:36 +02:00
|
|
|
@Input() form: FormGroup;
|
2017-12-11 14:47:52 +01:00
|
|
|
@Input() pathName: string;
|
2017-10-06 16:33:08 +02:00
|
|
|
|
2017-12-11 14:47:52 +01:00
|
|
|
@Input() path: string;
|
|
|
|
|
|
|
|
|
2018-07-11 15:47:36 +02:00
|
|
|
constructor(public visibilityRulesService: VisibilityRulesService) {
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-11-23 11:40:02 +01:00
|
|
|
//let st = this.group.style == "any" ? "" : this.group.style;
|
|
|
|
//this.classFromJson = this.group.class == "" ? "" : this.group.class;
|
2017-10-06 16:33:08 +02:00
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
/* this.customStyle = {};
|
2017-10-06 16:33:08 +02:00
|
|
|
if (st != "") {
|
|
|
|
st.replace(/"/g, '\\"');
|
|
|
|
|
|
|
|
var attributes = st.split(';');
|
|
|
|
for (var i = 0; i < attributes.length; i++) {
|
|
|
|
var entry = attributes[i].split(':');
|
|
|
|
entry[1].replace(/["]/g, " ");
|
|
|
|
//this.customStyle[entry[0]] = '2px solid #c1baba';
|
|
|
|
var a = entry[0];
|
|
|
|
this.customStyle[a] = entry[1];
|
2017-11-23 11:40:02 +01:00
|
|
|
} */
|
|
|
|
}
|
2017-10-06 16:33:08 +02:00
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-12-11 14:47:52 +01:00
|
|
|
addMultipleField(fieldsetIndex: number) {
|
2017-12-11 16:35:51 +01:00
|
|
|
let compositeField: CompositeField = this.group.compositeFields[fieldsetIndex].cloneForMultiplicity(fieldsetIndex);
|
2017-12-11 14:47:52 +01:00
|
|
|
this.group.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField);
|
|
|
|
(<FormArray>(this.form.get("compositeFields").get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
|
|
|
}
|
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
addFieldSet() {
|
|
|
|
/* debugger;
|
2017-11-15 15:43:14 +01:00
|
|
|
let subgroup: any = {};
|
2017-11-23 11:40:02 +01:00
|
|
|
this.group.compositeFields.groupFields.forEach((field, i) => {
|
|
|
|
debugger;
|
|
|
|
this.form.addControl(field.key + "_" + i, new FormControl(""))
|
2017-11-15 15:43:14 +01:00
|
|
|
|
|
|
|
if (field.controlType == "textbox") {
|
|
|
|
let newfield: FieldBase<any>;
|
|
|
|
let rule = new Rule();
|
|
|
|
newfield = new TextboxField({
|
2017-11-23 11:40:02 +01:00
|
|
|
label: field.label + "_" + i,
|
|
|
|
key: field.key + "_" + i,
|
|
|
|
value: "",
|
|
|
|
order: field.order,
|
|
|
|
rules: field.rules,
|
|
|
|
visible: field.visible,
|
|
|
|
group: field.group,
|
|
|
|
description: field.description
|
2017-11-15 15:43:14 +01:00
|
|
|
});
|
|
|
|
this.group.compositeFields.groupFields.push(newfield)
|
2017-11-23 11:40:02 +01:00
|
|
|
}
|
2017-11-15 15:43:14 +01:00
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
}); */
|
2017-11-15 15:43:14 +01:00
|
|
|
}
|
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|