Fix form event listener

This commit is contained in:
Preston Doman 2019-02-09 23:02:01 -08:00
parent da50627f51
commit 5427c026cf
2 changed files with 8 additions and 6 deletions

View file

@ -419,13 +419,15 @@ document.addEventListener("click", function(event) {
}
});
document.addEventListener("submit", function(event) {
const newReportForm = document.querySelector(".new-report-form");
if (newReportForm) {
newReportForm.addEventListener("submit", function(event) {
event.preventDefault();
if (event.target.classList.contains("new-report")) {
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();
});
}

View file

@ -44,7 +44,7 @@
<h3>Create a new report</h3>
</div>
<div class="card-body">
<form class="form new-report" autocomplete="off">
<form class="form new-report-form" autocomplete="off">
<div class="form-group">
<label for="title">Report title:</label>
<input type="text" class="form-control" name="title" id="title">