From 35e6dede098b46c1d0b851281657b5e03c82061d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Mar 2022 11:34:14 -0700 Subject: [PATCH] Script to remove input fields --- bookwyrm/static/js/forms.js | 17 +++++++++++++++++ .../templates/book/edit/edit_book_form.html | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bookwyrm/static/js/forms.js b/bookwyrm/static/js/forms.js index 7d946d147..998873898 100644 --- a/bookwyrm/static/js/forms.js +++ b/bookwyrm/static/js/forms.js @@ -1,6 +1,19 @@ (function () { "use strict"; + /** + * Remoev input field + * + * @param {event} the button click event + */ + function removeInput(event) { + const trigger = event.currentTarget; + const input_id = trigger.dataset.remove; + const input = document.getElementById(input_id); + + input.remove(); + } + /** * Duplicate an input field * @@ -29,4 +42,8 @@ document .querySelectorAll("[data-duplicate]") .forEach((node) => node.addEventListener("click", duplicateInput)); + + document + .querySelectorAll("[data-remove]") + .forEach((node) => node.addEventListener("click", removeInput)); })(); diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index d886d12f7..fc15d26ae 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -87,12 +87,16 @@ -
+
-