export class FormSectionUI extends FormSection { constructor(formSection: FormSection) { this.SectionDisplayId = 'section' + this.SectionId.toString(); } SectionDisplayId: string; FieldsUI: Array<FormFieldUI>; HiddenFieldsUI: Array<FormFieldUI>; SectionFormGroup: FormGroup; MainFormGroup: FormGroup; ParentFormSchemaUI: FormSchemaUI; static fromFormSectionData(formSection: FormSection): FormSectionUI { let formSectionUI = new FormSectionUI(formSection); formSectionUI.FieldsUI = new Array<FormFieldUI>(); formSectionUI.HiddenFieldsUI = new Array<FormFieldUI>(); formSectionUI.Fields.forEach(field => { let fieldUI = FormFieldUI.fromFormFieldData(field); if (fieldUI.ColumnType != 'HIDDEN') formSectionUI.FieldsUI.push(fieldUI); else formSectionUI.HiddenFieldsUI.push(fieldUI); }); formSectionUI.SectionFormGroup = FormSectionUI.buildFormSectionFormGroup(formSectionUI); return formSectionUI; } static buildFormSectionFormGroup(formSectionUI: FormSectionUI): FormGroup { let obj = {}; formSectionUI.FieldsUI.forEach(fieldUI => { obj[fieldUI.FieldDisplayId] = fieldUI.FieldFormControl; }); let sectionFormGroup = new FormGroup(obj); return sectionFormGroup; } } =============================================
export class FormFieldUI extends FormField { constructor(formField: FormField) { super(); this.FieldDisplayId = 'field' + this.FieldId.toString(); this.ListItems = new Array<SelectListItem>(); } public FieldDisplayId: string; public FieldFormControl: FormControl; public ParentSectionFormGroup: FormGroup; public MainFormGroup: FormGroup; public ParentFormSectionUI: FormSectionUI; public ValueChange: EventEmitter<any> = new EventEmitter<any>(); static buildFormControl(formFieldUI:FormFieldUI): FormControl { let nullValidator = Validators.nullValidator; let fieldKey: string = formFieldUI.FieldDisplayId; let fieldValue: any; switch (formFieldUI.ColumnType) { default: fieldValue = formFieldUI.Value; break; } let isDisabled = !formFieldUI.IsEnabled; let validatorsArray: ValidatorFn[] = new Array<ValidatorFn>(); let asyncValidatorsArray: AsyncValidatorFn[] = new Array<AsyncValidatorFn>(); let formControl = new FormControl({ value: fieldValue, disabled: isDisabled }, validatorsArray, asyncValidatorsArray); return formControl; } }