From 1887cc406bb2c7c3933b95fa53941ac3bb0edd59 Mon Sep 17 00:00:00 2001 From: eclipse Date: Tue, 3 Jun 2025 11:24:34 +0200 Subject: [PATCH] streamlined behavior of form modal on different events: - enter key - escape key - click close button - click submit button - click cancel button - click outside of modal note: right now the corrections only affect genre.html; changes will need to be carried over to other templates --- the_works/static/js/modal.js | 8 +++++--- the_works/templates/views/genre.html | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/the_works/static/js/modal.js b/the_works/static/js/modal.js index 002592a..b182ec4 100644 --- a/the_works/static/js/modal.js +++ b/the_works/static/js/modal.js @@ -11,10 +11,11 @@ function initModal(modal_id, input_ids, headings, form_actions) { for (const el of document.querySelectorAll('.action-update')) { el.addEventListener("click", event => showDialog(modal_id, input_ids, headings[1], form_actions[1], input_ids.map(input => event.currentTarget.dataset[input.slice(5).toLowerCase()]), event.currentTarget.dataset.id)); } - // add event listener to close button - document.querySelector("dialog button.modal-close").addEventListener("click", event => { +/* // add event listener to close button + document.querySelector("dialog button.modal-close").addEventListener("click", event => { event.target.closest("dialog").close(); - }); + event.preventDefault(); + }); */ } @@ -27,6 +28,7 @@ function showDialog(modal_id, input_ids, heading, form_action, input_values, url // set modal attributes document.getElementById("dialog-heading").textContent = heading; document.getElementById("form_submit").formAction = form_action; + document.getElementById("form_submit").form.action = form_action; for (var i = 0; i < input_ids.length; i++ ) { document.getElementById(input_ids[i]).value = input_values[i] || ""; } diff --git a/the_works/templates/views/genre.html b/the_works/templates/views/genre.html index 79fd699..c6f3f88 100644 --- a/the_works/templates/views/genre.html +++ b/the_works/templates/views/genre.html @@ -32,10 +32,10 @@
-
+
- -

#

+ +