Skip to content

Commit

Permalink
Adds autosave htmx functionality to Visit update/create form
Browse files Browse the repository at this point in the history
  • Loading branch information
dc2007git committed May 30, 2024
1 parent 3729c62 commit 3f741bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion project/npda/templates/npda/visit_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<div class="bg-rcpch_light_blue py-8">
<div class="w-full max-w-3xl mx-auto px-2 py-4 m-2 shadow-md bg-white font-montserrat">
<strong>{{title}}</strong>
<form id="update-form" method="post" {% if form_method == "create" %} action="{% url 'visit-create' patient_id %}" {% else %} action="{% url 'visit-update' patient_id=patient_id pk=visit.pk %}" {% endif %}>
<form id="update-form" method="post" {% if form_method == "create" %} hx-post="{% url 'visit-create' patient_id %}" action="{% url 'visit-create' patient_id %}" {% else %} hx-post="{% url 'visit-update' patient_id=patient_id pk=visit.pk %}" action="{% url 'visit-update' patient_id=patient_id pk=visit.pk %}" {% endif %} hx-trigger="change delay:500ms" hx-target="#response"
hx-swap="innerHTML">
{% csrf_token %}
{% for field in form %}
{% if field.field.category is None %}
Expand Down Expand Up @@ -164,6 +165,7 @@
{% endif %}
</div>
</form>
<div id="response"></div>
</div>
</div>
{% endblock %}
2 changes: 2 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_htmx",
# "django.forms",
"rest_framework",
"drf_spectacular",
Expand All @@ -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",
]
Expand Down

0 comments on commit 3f741bd

Please sign in to comment.