From 5427c026cf0a69cf66ed4712b541e9720bfb9ae2 Mon Sep 17 00:00:00 2001 From: Preston Doman Date: Sat, 9 Feb 2019 23:02:01 -0800 Subject: [PATCH] Fix form event listener --- front/static/js/viewHistory.js | 12 +++++++----- front/static/new_report.html | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index c3ef7f9..aec0a8c 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -419,13 +419,15 @@ document.addEventListener("click", function(event) { } }); -document.addEventListener("submit", function(event) { - event.preventDefault(); - if (event.target.classList.contains("new-report")) { +const newReportForm = document.querySelector(".new-report-form"); +if (newReportForm) { + newReportForm.addEventListener("submit", function(event) { + event.preventDefault(); const url = getEndpointDomain() + "api/v1/report"; const payload = JSON.stringify({ "title": event.target.elements.title.value }); console.log("Payload:\n" + payload); const type = reportType.NEW; postDataToEndpoint(url, payload, createReportForm, type); - } -}); + this.reset(); + }); +} diff --git a/front/static/new_report.html b/front/static/new_report.html index 2d925a1..daf4c54 100644 --- a/front/static/new_report.html +++ b/front/static/new_report.html @@ -44,7 +44,7 @@

Create a new report

-
+