From 0b67a45d60e6976fa1267ee4894e625b415a7d00 Mon Sep 17 00:00:00 2001 From: Christina Sarai Atoche Pascual Date: Sun, 8 Sep 2024 09:44:25 -0500 Subject: [PATCH] feature: agrega boton quitar filtros --- js/app.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/js/app.js b/js/app.js index 1451637..57ded38 100644 --- a/js/app.js +++ b/js/app.js @@ -7,6 +7,7 @@ document.addEventListener('DOMContentLoaded', function(){ const paginas = document.querySelector('#paginas'); const editorial = document.querySelector('#editorial'); const resultContent = document.querySelector('#resultContent'); + const btnReset = document.querySelector('#btnReset'); // asigna valores seleccionados let form = { @@ -25,6 +26,7 @@ document.addEventListener('DOMContentLoaded', function(){ idioma.addEventListener('change', filter); paginas.addEventListener('change', filter); editorial.addEventListener('change', filter); + btnReset.addEventListener('click', resetSelects); showResult(books) @@ -39,8 +41,6 @@ document.addEventListener('DOMContentLoaded', function(){ bookItem.innerHTML = ` ${nombre} ${autor} ${categoria} ${año} ${idioma} ${npaginas} pag. ${editorial} ` - // bookItem.textContent = `${categoria} - ${autor} - ${año} - ${idioma} - ${paginas} - ${editorial}`; - resultContent.append(bookItem); }) } @@ -49,7 +49,6 @@ document.addEventListener('DOMContentLoaded', function(){ // filtra segun elección function filter(event) { form[event.target.name] = event.target.value; - console.log(form) const newResult = books.filter(filterCategory).filter(filterAuthor).filter(filterYear).filter(filterLenguage).filter(filterPage).filter(filterEditorial); @@ -126,4 +125,19 @@ document.addEventListener('DOMContentLoaded', function(){ resultContent.removeChild(resultContent.firstChild); } } + + + // resetea los campos select + function resetSelects() { + form = { + categoria: '', + autor: '', + año: '', + idioma: '', + paginas: '', + editorial: '', + }; + + showResult(books) + } }) \ No newline at end of file