From e8c3da4ac8d809897916e3dc17e95a0bc217758f Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sat, 14 Oct 2023 16:57:22 -0400 Subject: [PATCH] re-render when children's checkbox toggles --- frontend/files/app.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/files/app.js b/frontend/files/app.js index 2067c13..fb4cd0c 100644 --- a/frontend/files/app.js +++ b/frontend/files/app.js @@ -9,21 +9,28 @@ function init() { .then((books) => { // prepare response books.forEach(apiResponseParsing); - document.getElementById("search").addEventListener("input", (e) => { - renderTable( - search( - books, - e.target.value, - document.getElementById("childrens").checked - ) - ); - }); + document + .getElementById("search") + .addEventListener("input", triggerUpdate); + document + .getElementById("childrens") + .addEventListener("change", triggerUpdate); renderTable( search(books, "", document.getElementById("childrens").checked) ); }); } +function triggerUpdate() { + renderTable( + search( + books, + document.getElementById("search").value, + document.getElementById("childrens").checked + ) + ); +} + function renderTable(books, sortField) { if (sortField) { if (sortState.sortBy === sortField && sortState.sortOrder === "asc") {