shows-admin/src/components/delete-modal/delete-modal.component.ts
2025-02-06 10:49:06 +01:00

47 lines
1.3 KiB
TypeScript

import {Component, inject} from '@angular/core';
import {NgbActiveModal, NgbCollapse} from '@ng-bootstrap/ng-bootstrap';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
@Component({
selector: 'app-delete-modal',
imports: [
NgbCollapse,
FormsModule,
ReactiveFormsModule
],
templateUrl: './delete-modal.component.html',
styleUrl: './delete-modal.component.css'
})
export class DeleteModalComponent {
protected activeModal: NgbActiveModal = inject(NgbActiveModal)
showName: string = ""
formHidden: boolean = true;
buttonDisabled: boolean = false;
confirmationForm: FormGroup
constructor() {
this.confirmationForm = new FormGroup({
name: new FormControl("", Validators.required)
})
}
deletePressed() {
if (this.formHidden) {
// Only add the control the first time the button is pressed
const regex = new RegExp(this.showName)
const control = new FormControl("", [Validators.required, Validators.pattern(regex)])
this.confirmationForm.setControl("name", control)
this.formHidden = false;
this.buttonDisabled = true;
} else {
this.formSubmitted()
}
}
formSubmitted() {
if (this.confirmationForm.valid) {
this.activeModal.close(true)
}
}
}