Skip to content

Commit

Permalink
search on enter
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazerYoo committed Aug 9, 2024
1 parent ea63412 commit 234afab
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ document
});
});

// handle filter search queries
// handle filter search queries on input
document.getElementById("search-query").addEventListener("input", (event) => {
console.log(event.target.value);
// clear output
Expand All @@ -43,3 +43,24 @@ document.getElementById("search-query").addEventListener("input", (event) => {
stats(results);
}
});

// handle filter search queries on enter
document.getElementById("search-query").addEventListener("keydown", (event) => {
if (event.key === "Enter") {
const query = document.getElementById("search-query").value;
console.log(query);
// clear output
clearTableOutput();
clearStatsOutput();

// show all rooms when empty query
if (query === "") {
tablulate(globalRooms);
stats(globalRooms);
} else {
const results = search(globalRooms, query);
tablulate(results);
stats(results);
}
}
});

0 comments on commit 234afab

Please sign in to comment.