From 4e798558115a71c61d9a5f77a909356aeb0873b6 Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <fuhse@data-quest.de>
Date: Tue, 28 May 2024 04:50:35 +0000
Subject: [PATCH] Resolve "VA-Administration: Filter nach Text-Datenfelder
 funktionieren nicht"

Closes #4215

Merge request studip/studip!3042
---
 templates/sidebar/search-widget.php | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/templates/sidebar/search-widget.php b/templates/sidebar/search-widget.php
index 6d870ba246a..5bbc77e48ee 100644
--- a/templates/sidebar/search-widget.php
+++ b/templates/sidebar/search-widget.php
@@ -1,6 +1,7 @@
 <form action="<?= URLHelper::getLink($url) ?>"
       method="<?= $method ?>"
-      <? if (isset($id)) printf('id="%s"', htmlReady($id)); ?>
+      <? $id = $id ?? 'form-'.md5(uniqid()) ?>
+      <? printf('id="%s"', htmlReady($id)) ?>
       <?= $onsubmit ? 'onsubmit="'.htmlReady($onsubmit).'"' : '' ?>
       class="sidebar-search">
 <? foreach ($url_params as $key => $value): ?>
@@ -8,9 +9,10 @@
 <? endforeach; ?>
     <ul class="needles">
     <? foreach ($needles as $needle): ?>
+        <? $hash = md5($url . '|' . $needle['name']) ?>
         <li <? if ($needle['quick_search'] && $needle['quick_search']->hasExtendedLayout()) echo 'class="extendedLayout" id="' . $needle['quick_search']->getId() . '_frame"'; ?>>
             <div class="input-group files-search">
-                <label for="needle-<?= $hash = md5($url . '|' . $needle['name']) ?>" <? if ($needle['placeholder']) echo 'style="display:none;"'; ?>>
+                <label for="needle-<?= $hash ?>" <? if ($needle['placeholder']) echo 'style="display:none;"'; ?>>
                     <?= htmlReady($needle['label']) ?>
                 </label>
                 <? if ($needle['quick_search']): ?>
@@ -23,10 +25,19 @@
                        <?= arrayToHtmlAttributes($needle['attributes']) ?>>
                 <? endif; ?>
                 <? if ($reset_link): ?>
-                    <a class="reset-search" href="<?= $reset_link ?>" tabindex="0" role="button"
-                       title="<?= _('Suche zurücksetzen') ?>">
-                        <?= Icon::create('decline')->asImg(20) ?>
-                    </a>
+                    <? if ($onsubmit) : ?>
+                        <?= Icon::create('decline')->asInput([
+                            'title' =>  _('Suche zurücksetzen'),
+                            'class' => 'reset-search',
+                            'onclick' => "window.document.getElementById('needle-".$hash."').value = '';"
+                        ]) ?>
+                    <? else : ?>
+                        <a class="reset-search" href="<?= $reset_link ?>" tabindex="0" role="button"
+                            <?= $onsubmit ? 'onclick="'."window.document.getElementById('needle-".$hash."').value = ''; window.document.getElementById('".$id."').submit(); return false; ".'"' : '' ?>
+                           title="<?= _('Suche zurücksetzen') ?>">
+                            <?= Icon::create('decline')->asImg(20) ?>
+                        </a>
+                    <? endif ?>
                 <? endif; ?>
                 <button type="submit" class="submit-search<?= $reset_link ? ' is-executed' : '' ?>"
                         title="<?= _('Suche ausführen') ?>">
-- 
GitLab