Components/create-edit-modal: fix date input in edit mode

This commit is contained in:
Toast 2025-02-05 02:13:13 +01:00
parent ef02fe8c82
commit ee6ebfd98c

View file

@ -5,6 +5,7 @@ import {ShowsApiService} from '../../../services/shows/shows-api.service';
import {ShowsApiCreation} from '../../../interfaces/shows-api-creation'; import {ShowsApiCreation} from '../../../interfaces/shows-api-creation';
import {ToastService} from '../../../services/toast/toast.service'; import {ToastService} from '../../../services/toast/toast.service';
import {Show} from '../../../interfaces/show'; import {Show} from '../../../interfaces/show';
import {formatDate} from '@angular/common';
@Component({ @Component({
selector: 'app-create-edit-modal', selector: 'app-create-edit-modal',
@ -28,13 +29,19 @@ export class CreateEditModalComponent {
} }
private initForm() { private initForm() {
let formattedDate: string
this.newShowForm = new FormGroup({ this.newShowForm = new FormGroup({
title: new FormControl(this.show?.title, Validators.required), title: new FormControl(this.show?.title, Validators.required),
date: new FormControl(this.show?.date, Validators.required),
seasons: new FormControl(this.show?.seasons, [Validators.required, Validators.min(1)]), seasons: new FormControl(this.show?.seasons, [Validators.required, Validators.min(1)]),
episodes: new FormControl(this.show?.episodes, [Validators.required, Validators.min(1)]), episodes: new FormControl(this.show?.episodes, [Validators.required, Validators.min(1)]),
description: new FormControl(this.show?.description, Validators.required) description: new FormControl(this.show?.description, Validators.required)
}) })
if (this.show?.date !== undefined) {
formattedDate = formatDate(this.show?.date, "YYYY-MM-dd", "en")
} else {
formattedDate = ""
}
this.newShowForm.addControl("date", new FormControl(formattedDate, Validators.required))
} }
protected dismiss() { protected dismiss() {