From dfd51c1343b150136ce3bf6eaf74230f4b6056c8 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 15 May 2026 12:50:32 -0400 Subject: [PATCH] [birds] Add small js file for form --- .../apps/birds/static/birds/bird_sightings.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 vrobbler/apps/birds/static/birds/bird_sightings.js diff --git a/vrobbler/apps/birds/static/birds/bird_sightings.js b/vrobbler/apps/birds/static/birds/bird_sightings.js new file mode 100644 index 0000000..d422ad3 --- /dev/null +++ b/vrobbler/apps/birds/static/birds/bird_sightings.js @@ -0,0 +1,27 @@ +document.addEventListener("DOMContentLoaded", function () { + var widget = document.querySelector(".bird-sightings-widget"); + if (!widget) return; + + var list = widget.querySelector(".bird-sightings-list"); + + widget.addEventListener("click", function (e) { + if (e.target.classList.contains("add-sighting-row")) { + var rows = list.querySelectorAll(".bird-sighting-row"); + var template = rows[rows.length - 1]; + if (!template) return; + var clone = template.cloneNode(true); + clone.querySelectorAll("select, input").forEach(function (el) { + el.value = ""; + }); + clone.querySelector('input[name$="_quantity"]').value = "1"; + list.appendChild(clone); + } + + if (e.target.classList.contains("remove-sighting")) { + var rows = list.querySelectorAll(".bird-sighting-row"); + if (rows.length > 1) { + e.target.closest(".bird-sighting-row").remove(); + } + } + }); +});