diff --git a/src/components/EventForm.vue b/src/components/EventForm.vue index 00a6c5f..69b37b9 100644 --- a/src/components/EventForm.vue +++ b/src/components/EventForm.vue @@ -113,6 +113,31 @@ import Multiselect from 'vue-multiselect'; import { formatTime } from '@/utils/strings'; import AddImageDialog from '@/components/AddImageDialog.vue'; +function normalizeDateForInput(value) { + if (!value) return ''; + if (value instanceof Date && !Number.isNaN(value.getTime())) { + const yyyy = value.getFullYear(); + const mm = String(value.getMonth() + 1).padStart(2, '0'); + const dd = String(value.getDate()).padStart(2, '0'); + return `${yyyy}-${mm}-${dd}`; + } + const raw = String(value).trim(); + // ISO oder SQL-Format: YYYY-MM-DD... + const isoMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})/); + if (isoMatch) { + return `${isoMatch[1]}-${isoMatch[2]}-${isoMatch[3]}`; + } + // Deutsches Format: DD.MM.YYYY + const deMatch = raw.match(/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/); + if (deMatch) { + const dd = String(deMatch[1]).padStart(2, '0'); + const mm = String(deMatch[2]).padStart(2, '0'); + const yyyy = deMatch[3]; + return `${yyyy}-${mm}-${dd}`; + } + return ''; +} + export default { name: 'EventForm', components: { Multiselect, AddImageDialog }, @@ -140,7 +165,10 @@ export default { }, data() { return { - eventData: { ...this.event }, + eventData: { + ...this.event, + date: normalizeDateForInput(this.event?.date), + }, selectedEventType: null, selectedInstitution: this.event.institution || null, selectedEventPlace: this.event.eventPlace || null, @@ -308,9 +336,7 @@ export default { }, normalizeEventForForm(event) { const normalized = { ...(event || {}) }; - if (typeof normalized.date === 'string') { - normalized.date = normalized.date.split('T')[0]; - } + normalized.date = normalizeDateForInput(normalized.date); const dayValue = this.extractDayOfWeekValue(normalized.dayOfWeek); if (dayValue > -1) { const mappedValue = dayValue === 0 ? 7 : dayValue;