From d0baa11d3ba1b6514b1993a9f483a28089590e60 Mon Sep 17 00:00:00 2001
From: Nico Athanassiadis <nico@dsv.su.se>
Date: Tue, 19 Nov 2024 10:06:43 +0100
Subject: [PATCH] Fixed behavior of valid from date when creating new template

Previously if you created a new grading template chose a date for `Valid from` field and then added a criterion.
The valid from date would reset to null. This would create a validation error on save.
This creates unnecessary confusion for the user.

Now when you have chosen a date and then choose to add a criterion to the template the date does not reset.

The reason for this was that the AutoSave() added to the field was using the wrong event to trigger the setValidFrom().
Since we use bootstraps date picker we have to trigger on "changeDate" event.
---
 .../pages/grading/EditingGradingTemplateComponentPanel.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/view/src/main/java/se/su/dsv/scipro/admin/pages/grading/EditingGradingTemplateComponentPanel.java b/view/src/main/java/se/su/dsv/scipro/admin/pages/grading/EditingGradingTemplateComponentPanel.java
index 6c28a46bde..47afb417b1 100644
--- a/view/src/main/java/se/su/dsv/scipro/admin/pages/grading/EditingGradingTemplateComponentPanel.java
+++ b/view/src/main/java/se/su/dsv/scipro/admin/pages/grading/EditingGradingTemplateComponentPanel.java
@@ -37,7 +37,7 @@ class EditingGradingTemplateComponentPanel extends GenericPanel<EditingGradingTe
                         EditingGradingTemplate::setValidFrom),
                 LocalDate.class);
         validFromField.add(new BootstrapDatePicker());
-        validFromField.add(new AutoSave());
+        validFromField.add(new AutoSave("changeDate"));
         add(validFromField);
 
         add(new TextArea<>("note", LambdaModel.of(
@@ -298,6 +298,10 @@ class EditingGradingTemplateComponentPanel extends GenericPanel<EditingGradingTe
             super("input");
         }
 
+        public AutoSave(String event) {
+            super(event);
+        }
+
         @Override
         protected void onUpdate(AjaxRequestTarget target) {
             // just trigger the ajax call is enough to update the model object