import { DataModel } from '../../entities/DataModel'; import { GroupBase } from './group-base'; import { Component, Input, OnInit } from '@angular/core'; import { FormGroup, Validators, FormControl } from '@angular/forms'; import { NgForm } from '@angular/forms'; import { FieldBase } from '../fields/field-base'; import { TextboxField } from '../fields/textbox/field-textbox'; import { Rule } from '../../entities/common/rule'; @Component({ selector: 'df-group', templateUrl: './dynamic-form-group.component.html', styleUrls: ['./dynamic-form-group.component.css'] }) export class DynamicFormGroupComponent implements OnInit { @Input() dataModel: DataModel; @Input() group: GroupBase; @Input() form: FormGroup; @Input() customStyle: {}; @Input() classFromJson: string ; constructor() { } ngOnInit() { let st = this.group.style == "any" ? "" : this.group.style; this.classFromJson = this.group.class == "" ? "" : this.group.class; this.customStyle = {}; 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]; } } } addFieldSet(){ debugger; let subgroup: any = {}; this.group.compositeFields.groupFields.forEach((field, i )=>{ debugger; this.form.addControl(field.key +"_"+i, new FormControl("") ) if (field.controlType == "textbox") { let newfield: FieldBase; let rule = new Rule(); newfield = new TextboxField({ label: field.label+"_"+i, key: field.key +"_"+i, value: "", order: field.order, rules: field.rules, visible: field.visible, group: field.group, description: field.description }); this.group.compositeFields.groupFields.push(newfield) } }); } shouldIShow(){ this.group.compositeFields.groupFields.forEach((field, i )=>{ if(field.visible) return true; }) } }