From 6637a6df976bd1434fc5ef559195d2528c797070 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Wed, 5 Mar 2025 16:06:59 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20convert=20htmx=20dynsel?= =?UTF-8?q?=20search=20method=20to=20GET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a bug where, when contained in a form with multiple fields named "q", the search would not work since HTMX is including all fields of the parent form. --- scipost_django/common/templates/htmx/dynsel.html | 8 ++++---- .../common/templates/htmx/dynsel_list_page.html | 2 +- scipost_django/common/views.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scipost_django/common/templates/htmx/dynsel.html b/scipost_django/common/templates/htmx/dynsel.html index 91556f2a4..e60baea57 100644 --- a/scipost_django/common/templates/htmx/dynsel.html +++ b/scipost_django/common/templates/htmx/dynsel.html @@ -9,17 +9,17 @@ </div> {% include "django/forms/widgets/select.html" %} - + <input name="q" value="{{ initial }}" type="text" - hx-post="{{ url }}" + hx-get="{{ url }}" hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" hx-target="next .result-list" /> </div> - + <ul class="result-list"> </ul> - + </div> diff --git a/scipost_django/common/templates/htmx/dynsel_list_page.html b/scipost_django/common/templates/htmx/dynsel_list_page.html index ea61e616c..ed3955d63 100644 --- a/scipost_django/common/templates/htmx/dynsel_list_page.html +++ b/scipost_django/common/templates/htmx/dynsel_list_page.html @@ -14,7 +14,7 @@ {% if page_obj.has_next %} <li class="htmx-indicator w-100 d-flex justify-content-center bg-primary bg-opacity-25" - hx-post="{{ request.path }}?page={{ page_obj.next_page_number }}" + hx-get="{{ request.path }}?page={{ page_obj.next_page_number }}" hx-include="previous input" hx-trigger="intersect once" hx-swap="outerHTML" diff --git a/scipost_django/common/views.py b/scipost_django/common/views.py index d979cfdd9..de650ea56 100644 --- a/scipost_django/common/views.py +++ b/scipost_django/common/views.py @@ -171,9 +171,9 @@ class HXDynselAutocomplete(View): template_name = "htmx/dynsel_list_page.html" paginate_by = 16 - def post(self, request): + def get(self, request): self.page_nr = request.GET.get("page") - self.q = request.POST.get("q", "") + self.q = request.GET.get("q", "") context = self.get_context_data() -- GitLab