You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { VisibilityRulesService } from '../../utilities/visibility-rules/visibility-rules.service';
|
|
import { FormGroup, Form, FormArray } from '@angular/forms';
|
|
import { Component, Input, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
|
|
import { CompositeField } from '../../models/CompositeField';
|
|
import { Section } from '../../models/Section';
|
|
|
|
|
|
@Component({
|
|
selector: 'df-section',
|
|
templateUrl: './dynamic-form-section.html',
|
|
styleUrls: [
|
|
'./dynamic-form-section.css'
|
|
],
|
|
encapsulation: ViewEncapsulation.None,
|
|
})
|
|
export class DynamicFormSectionComponent implements OnInit {
|
|
|
|
@Input() section: Section
|
|
form: FormGroup;
|
|
@Input() pathName: string;
|
|
@Input() path: string;
|
|
trackByFn = (index, item) => item ? item["id"] : null
|
|
constructor(public visibilityRulesService: VisibilityRulesService) { }
|
|
|
|
ngOnInit() {
|
|
if (this.section) {
|
|
this.form = this.visibilityRulesService.getFormGroup(this.section.id)
|
|
}
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
this.visibilityRulesService.triggerVisibilityEvaluation()
|
|
}
|
|
|
|
addMultipleField(fieldsetIndex: number) {
|
|
let compositeField: CompositeField = this.section.compositeFields[fieldsetIndex].cloneForMultiplicity(fieldsetIndex);
|
|
this.section.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField);
|
|
(<FormArray>(this.form.get("compositeFields").get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
|
}
|
|
|
|
isElementVisible(fieldSet: CompositeField): boolean {
|
|
if (!fieldSet) return false;
|
|
for (var i = 0; i < fieldSet.fields.length; i++) {
|
|
if (fieldSet.fields[i])
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|