diff --git a/script.js b/script.js index 8a43ebc..77451db 100644 --- a/script.js +++ b/script.js @@ -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 @@ -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); + } + } +});