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

40 lines
1.6 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateSelectDataEditorModel, DescriptionTemplateSelectOptionEditorModel } from '../../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-select-field-component',
styleUrls: ['./description-template-editor-select-field.component.scss'],
templateUrl: './description-template-editor-select-field.component.html'
})
export class DescriptionTemplateEditorSelectFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() validationRootPath: string;
ngOnInit() {
}
addNewRow() {
const selectOptions: DescriptionTemplateSelectOptionEditorModel = new DescriptionTemplateSelectOptionEditorModel(this.validationErrorModel);
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
selectOptionsArray.push(selectOptions.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);
DescriptionTemplateSelectDataEditorModel.reapplySelectValidators({
formGroup: this.form?.get('data') as UntypedFormGroup,
rootPath: `${this.validationRootPath}data.`,
validationErrorModel: this.validationErrorModel
});
this.form.get('data').get('options').markAsDirty();
}
}
}