From 2e61b9d855f4dbc69cfbd44fcf2a126aa9c1fe46 Mon Sep 17 00:00:00 2001
From: Ethan-clay03 <ethanclay2017@gmail.com>
Date: Fri, 3 Jan 2025 16:18:01 +0000
Subject: [PATCH] Added delay to search if username/email is available

---
 app/templates/profile/signup.html | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/app/templates/profile/signup.html b/app/templates/profile/signup.html
index 2484900..7f03243 100644
--- a/app/templates/profile/signup.html
+++ b/app/templates/profile/signup.html
@@ -71,12 +71,21 @@
         makeAjaxRequest("{{ url_for('profile.check_email') }}", { 'email': email }, 'email');
     }
 
-    document.getElementById('username').addEventListener('blur', function () {
+    function delayAvailabilityCheck(func, delay) {
+        let timer;
+        return function(...args) {
+            clearTimeout(timer);
+            timer = setTimeout(() => func.apply(this, args), delay);
+        };
+    }
+
+    document.getElementById('username').addEventListener('input', delayAvailabilityCheck(function () {
         checkUsernameAvailability(this.value);
-    });
+    }, 500));
 
-    document.getElementById('email').addEventListener('blur', function () {
+    document.getElementById('email').addEventListener('input', delayAvailabilityCheck(function () {
         checkEmailAvailability(this.value);
-    });
+    }, 500));
+
 </script>
 {% endblock %}
-- 
GitLab