From 647f833254e5a56c54eb17d6ac91fa72803325a8 Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <fuhse@data-quest.de>
Date: Wed, 29 May 2024 08:33:12 +0000
Subject: [PATCH] Resolve "TIC: Einfacheres Arbeiten mit dem Formbuilder"

Closes #4117

Merge request studip/studip!2960
---
 lib/classes/forms/Form.php                      |  2 ++
 lib/classes/forms/Input.php                     | 11 ++++++++---
 resources/assets/javascripts/bootstrap/forms.js | 10 +++++++---
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php
index 36a2e7d0fb2..9c22c4f397f 100644
--- a/lib/classes/forms/Form.php
+++ b/lib/classes/forms/Form.php
@@ -297,6 +297,8 @@ class Form extends Part
                     \PageLayout::postSuccess($this->success_message);
                 }
                 page_close();
+                //This indicates that the form has been stored successfully.
+                echo "STUDIPFORM_STORE_SUCCESS";
                 die();
             }
         }
diff --git a/lib/classes/forms/Input.php b/lib/classes/forms/Input.php
index 9d2ad327cae..ef506e9fe2f 100644
--- a/lib/classes/forms/Input.php
+++ b/lib/classes/forms/Input.php
@@ -150,12 +150,17 @@ abstract class Input
     }
 
     /**
-     * Returns the value of this input.
-     * @return null
+     * Returns the value of this input. If $this->value is a callable this->getValue() returns the computed result.
+     * @return mixed
      */
     public function getValue()
     {
-        return $this->value;
+        if (is_callable($this->value)) {
+            $callable = $this->value;
+            return $callable();
+        } else {
+            return $this->value;
+        }
     }
 
     /**
diff --git a/resources/assets/javascripts/bootstrap/forms.js b/resources/assets/javascripts/bootstrap/forms.js
index c34a0c1bf94..764361291f7 100644
--- a/resources/assets/javascripts/bootstrap/forms.js
+++ b/resources/assets/javascripts/bootstrap/forms.js
@@ -1,4 +1,5 @@
 import { $gettext, $gettextInterpolate } from '../lib/gettext';
+import Report from '../lib/report.js';
 
 // Allow fieldsets to collapse
 $(document).on(
@@ -291,9 +292,12 @@ STUDIP.ready(function () {
                                         url: v.STUDIPFORM_AUTOSAVEURL,
                                         data: params,
                                         type: 'post',
-                                        success() {
-                                            if (v.STUDIPFORM_REDIRECTURL) {
-                                                window.location.href = v.STUDIPFORM_REDIRECTURL
+                                        success(output) {
+                                            if (output === 'STUDIPFORM_STORE_SUCCESS' && v.STUDIPFORM_REDIRECTURL) {
+                                                //The form has been stored successfully:
+                                                window.location.href = v.STUDIPFORM_REDIRECTURL;
+                                            } else if (output !== 'STUDIPFORM_STORE_SUCCESS') {
+                                                Report.error($gettext('Es ist ein Fehler aufgetreten'), output);
                                             }
                                         }
                                     });
-- 
GitLab