From 0ae44ed51b997ca98bce6a21034522e4af95381c Mon Sep 17 00:00:00 2001
From: Hangzhi Yu <hangzhi@protonmail.com>
Date: Mon, 9 Dec 2024 13:21:17 +0100
Subject: [PATCH] Reset validation status after entering start/end datetimes in
 absence creation form

---
 .../components/coursebook/Coursebook.vue      |  6 ++----
 .../absences/AbsenceCreationForm.vue          | 20 ++++++++++++++-----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
index bf9d99bd..60e4dae7 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
@@ -56,7 +56,7 @@
           :subjects="subjects"
           :documentation="item"
           :affected-query="lastQuery"
-          :value="(selectedParticipations[item.id] ??= [])"
+          :value="selectedParticipations[item.id] ??= []"
           @input="selectParticipation(item.id, $event)"
         />
       </template>
@@ -69,9 +69,7 @@
         <DocumentationLoader />
       </template>
     </infinite-scrolling-date-sorted-c-r-u-d-iterator>
-    <absence-creation-dialog
-      :absence-reasons="absenceReasons"
-    />
+    <absence-creation-dialog :absence-reasons="absenceReasons" />
   </div>
 </template>
 
diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue b/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue
index 6da4703e..19dc5721 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue
@@ -1,5 +1,5 @@
 <template>
-  <v-form @input="$emit('valid', $event)">
+  <v-form ref="form" @input="$emit('valid', $event)">
     <v-container>
       <v-row>
         <div aria-required="true" class="full-width">
@@ -148,17 +148,27 @@ export default {
       const parsedStart = DateTime.fromISO(startDate);
       const parsedEnd = DateTime.fromISO(this.endDate);
       if (parsedStart >= parsedEnd) {
-        this.$emit('end-date', parsedStart.plus({ minutes: 5 }).toISO({ suppressSeconds: true }));
+        this.$emit(
+          "end-date",
+          parsedStart.plus({ minutes: 5 }).toISO({ suppressSeconds: true }),
+        );
       }
-      this.$emit('start-date', startDate);
+      this.$emit("start-date", startDate);
+      this.$refs.form.resetValidation();
+      this.$refs.form.validate();
     },
     handleEndDate(endDate) {
       const parsedStart = DateTime.fromISO(this.startDate);
       const parsedEnd = DateTime.fromISO(endDate);
       if (parsedEnd <= parsedStart) {
-        this.$emit('start-date', parsedEnd.minus({ minutes: 5 }).toISO({ suppressSeconds: true }));
+        this.$emit(
+          "start-date",
+          parsedEnd.minus({ minutes: 5 }).toISO({ suppressSeconds: true }),
+        );
       }
-      this.$emit('end-date', endDate);
+      this.$emit("end-date", endDate);
+      this.$refs.form.resetValidation();
+      this.$refs.form.validate();
     },
   },
 };
-- 
GitLab