From a485237456790d1f794dc0bb95bbe3cfe90e65d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 16 Nov 2023 19:03:16 +0100 Subject: [PATCH] Fix form not syncing due to HTMX --- games/forms.py | 1 + games/static/js/add_purchase.js | 1 + 2 files changed, 2 insertions(+) diff --git a/games/forms.py b/games/forms.py index 40d01c1..b67c294 100644 --- a/games/forms.py +++ b/games/forms.py @@ -59,6 +59,7 @@ class PurchaseForm(forms.ModelForm): related_purchase_by_edition_url = reverse("related_purchase_by_edition") self.fields["edition"].widget.attrs.update( { + "hx-trigger": "load, click", "hx-get": related_purchase_by_edition_url, "hx-target": "#id_related_purchase", "hx-swap": "outerHTML", diff --git a/games/static/js/add_purchase.js b/games/static/js/add_purchase.js index 8b26333..d593e48 100644 --- a/games/static/js/add_purchase.js +++ b/games/static/js/add_purchase.js @@ -25,6 +25,7 @@ function setupElementHandlers() { } document.addEventListener("DOMContentLoaded", setupElementHandlers); +document.addEventListener("htmx:afterSwap", setupElementHandlers); getEl("#id_type").onchange = () => { setupElementHandlers(); };