From 118446e792505478b25c6c60de814e8544aa3ac9 Mon Sep 17 00:00:00 2001
From: Vanessa Wiyono <13521151@std.stei.itb.ac.id>
Date: Thu, 5 Oct 2023 07:59:49 +0000
Subject: [PATCH] add debounce

---
 index.php | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/index.php b/index.php
index 87b6394..030ee54 100644
--- a/index.php
+++ b/index.php
@@ -100,7 +100,7 @@
                 <?php endif; ?>
                 <!-- Change input type to "text" for minimum stock -->
                 <input type="text" name="min_stock" placeholder="Min Stock" value="<?= htmlspecialchars($minStock) ?>">
-                <button type="submit">Search</button>
+                <button type="submit" id="search-button">Search</button>
             </form>
         </div>
 
@@ -126,6 +126,24 @@
             &copy; 2023 Ticket Ku. All rights reserved.
         </div>
     </div>
+
+    <script>
+        // disable search button temporarily (DEBOUNCE)
+        function disableSearchButton() {
+            const searchButton = document.getElementById("search-button");
+            searchButton.disabled = true;
+
+            setTimeout(() => {
+                searchButton.disabled = false;
+            }, 1200); // 0.8s delay
+        }
+
+        document.querySelector(".search-bar form").addEventListener("submit", function (e) {
+            e.preventDefault(); 
+            disableSearchButton();
+        });
+    </script>
+
 </body>
 
 </html>
-- 
GitLab