argos/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/radio-box/description-template-editor...

42 lines
1.8 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateRadioBoxDataEditorModel, DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-radio-box-field-component',
styleUrls: ['./description-template-editor-radio-box-field.component.scss'],
templateUrl: './description-template-editor-radio-box-field.component.html'
})
export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() validationRootPath: string;
ngOnInit() {
}
addNewRow() {
const radioListOptions: DescriptionTemplateRadioBoxOptionEditorModel = new DescriptionTemplateRadioBoxOptionEditorModel(this.validationErrorModel);
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
if (!selectOptionsArray) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); }
selectOptionsArray.push(radioListOptions.buildForm({rootPath: this.validationRootPath + 'data.options[' + selectOptionsArray.length + '].'}));
}
deleteRow(intex: number) {
if (this.form.get('data').get('options')) {
(<UntypedFormArray>this.form.get('data').get('options')).removeAt(intex);
DescriptionTemplateRadioBoxDataEditorModel.reapplyRadioBoxValidators({
formGroup: this.form.get('data') as UntypedFormGroup,
rootPath: `${this.validationRootPath}data.`,
validationErrorModel: this.validationErrorModel
});
this.form.get('data').get('options').markAsDirty();
}
}
}