From 3f741bd65732a05f2dc75b67da907b04a2bfb56f Mon Sep 17 00:00:00 2001 From: Danny Cowen Date: Thu, 30 May 2024 11:40:21 +0100 Subject: [PATCH 1/2] Adds autosave htmx functionality to Visit update/create form --- project/npda/templates/npda/visit_form.html | 4 +++- project/settings.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/project/npda/templates/npda/visit_form.html b/project/npda/templates/npda/visit_form.html index ba47c119..6d9e1b91 100644 --- a/project/npda/templates/npda/visit_form.html +++ b/project/npda/templates/npda/visit_form.html @@ -5,7 +5,8 @@
{{title}} -
+ {% csrf_token %} {% for field in form %} {% if field.field.category is None %} @@ -164,6 +165,7 @@ {% endif %}
+
{% endblock %} \ No newline at end of file diff --git a/project/settings.py b/project/settings.py index 77d9ef54..a2b6df5c 100644 --- a/project/settings.py +++ b/project/settings.py @@ -79,6 +79,7 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "django_htmx", # "django.forms", "rest_framework", "drf_spectacular", @@ -103,6 +104,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_htmx.middleware.HtmxMiddleware", # 2 factor authentication "django_otp.middleware.OTPMiddleware", ] From b07fd9cab66f3ef2bb5303fb09a23134f0b2a81f Mon Sep 17 00:00:00 2001 From: Danny Cowen Date: Fri, 31 May 2024 10:21:42 +0100 Subject: [PATCH 2/2] Fix hx-swap bug where form was rendering at bottom of page --- project/npda/templates/npda/visit_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/npda/templates/npda/visit_form.html b/project/npda/templates/npda/visit_form.html index 6d9e1b91..c9a52263 100644 --- a/project/npda/templates/npda/visit_form.html +++ b/project/npda/templates/npda/visit_form.html @@ -6,7 +6,7 @@
{{title}}
+ hx-swap="none"> {% csrf_token %} {% for field in form %} {% if field.field.category is None %}