From b2b946d36b48f535ec56516cf273e17c734b83f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 06:20:45 +0000 Subject: [PATCH 1/5] Initial plan From 98e774144a74930416da5d29acbb6b05b7ae1761 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 06:25:41 +0000 Subject: [PATCH 2/5] Fix form issues: remove duplicate action, add accessibility, improve validation Co-authored-by: wildan3105 <7030099+wildan3105@users.noreply.github.com> --- public/js/form-validation.js | 20 ++++++++++++++++++++ src/pages/partials/body.handlebars | 19 ++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 public/js/form-validation.js diff --git a/public/js/form-validation.js b/public/js/form-validation.js new file mode 100644 index 00000000..b6f86783 --- /dev/null +++ b/public/js/form-validation.js @@ -0,0 +1,20 @@ +/* eslint-disable no-undef */ + +// Form validation for GitHub username search +document.getElementById('search-form').onsubmit = function() { + const inputField = document.getElementById('username'); + const username = inputField.value.trim(); + + if (username === '') { + alert('Username cannot be empty or contain only spaces.'); + return false; // Prevent form submission + } + + if (/\s/.test(inputField.value)) { + alert('Username cannot contain any spaces.'); + return false; + } + + showLoader(); + return true; // Allow form submission +}; diff --git a/src/pages/partials/body.handlebars b/src/pages/partials/body.handlebars index 004186c3..daa35ad7 100644 --- a/src/pages/partials/body.handlebars +++ b/src/pages/partials/body.handlebars @@ -10,11 +10,11 @@
-
+
- -
@@ -101,17 +101,6 @@ +
- - From 80fee51924367c3ad071e5f18a6cdac9567e54e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 06:27:02 +0000 Subject: [PATCH 3/5] Address code review: use consistent validation and specific eslint comment Co-authored-by: wildan3105 <7030099+wildan3105@users.noreply.github.com> --- public/js/form-validation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/form-validation.js b/public/js/form-validation.js index b6f86783..d303c82e 100644 --- a/public/js/form-validation.js +++ b/public/js/form-validation.js @@ -1,4 +1,4 @@ -/* eslint-disable no-undef */ +/* global showLoader */ // Form validation for GitHub username search document.getElementById('search-form').onsubmit = function() { @@ -10,7 +10,7 @@ document.getElementById('search-form').onsubmit = function() { return false; // Prevent form submission } - if (/\s/.test(inputField.value)) { + if (/\s/.test(username)) { alert('Username cannot contain any spaces.'); return false; } From 440f092e8dd06c15db544599188db5757efdd84b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 06:28:32 +0000 Subject: [PATCH 4/5] Fix validation logic: check original value for spaces per code review Co-authored-by: wildan3105 <7030099+wildan3105@users.noreply.github.com> --- public/js/form-validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/form-validation.js b/public/js/form-validation.js index d303c82e..a55da2e3 100644 --- a/public/js/form-validation.js +++ b/public/js/form-validation.js @@ -10,7 +10,7 @@ document.getElementById('search-form').onsubmit = function() { return false; // Prevent form submission } - if (/\s/.test(username)) { + if (/\s/.test(inputField.value)) { alert('Username cannot contain any spaces.'); return false; } From 7613cb92327a7782432b194d2f4e00fb7b1bd4da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 06:42:24 +0000 Subject: [PATCH 5/5] Auto-remove spaces from username instead of showing error Co-authored-by: wildan3105 <7030099+wildan3105@users.noreply.github.com> --- public/js/form-validation.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/public/js/form-validation.js b/public/js/form-validation.js index a55da2e3..9df36e6e 100644 --- a/public/js/form-validation.js +++ b/public/js/form-validation.js @@ -3,17 +3,16 @@ // Form validation for GitHub username search document.getElementById('search-form').onsubmit = function() { const inputField = document.getElementById('username'); - const username = inputField.value.trim(); + // Auto-remove all spaces from the username + const username = inputField.value.replace(/\s/g, ''); if (username === '') { - alert('Username cannot be empty or contain only spaces.'); + alert('Username cannot be empty.'); return false; // Prevent form submission } - if (/\s/.test(inputField.value)) { - alert('Username cannot contain any spaces.'); - return false; - } + // Update the input field with the cleaned value + inputField.value = username; showLoader(); return true; // Allow form submission