From a46255ddda73e1e29c610d40aeb7054214014935 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 3 Oct 2023 16:29:55 -0400 Subject: [PATCH] Fixes #13064: Ensure unchecked checkboxes do not revert to original values upon HTMX form refresh --- netbox/netbox/settings.py | 4 ++++ netbox/templates/django/forms/widgets/checkbox.html | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 netbox/templates/django/forms/widgets/checkbox.html diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 8be2800fb..975e86858 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -355,6 +355,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', + 'django.forms', 'corsheaders', 'debug_toolbar', 'graphiql_debug_toolbar', @@ -430,6 +431,9 @@ TEMPLATES = [ }, ] +# This allows us to override Django's stock form widget templates +FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' + # Set up authentication backends if type(REMOTE_AUTH_BACKEND) not in (list, tuple): REMOTE_AUTH_BACKEND = [REMOTE_AUTH_BACKEND] diff --git a/netbox/templates/django/forms/widgets/checkbox.html b/netbox/templates/django/forms/widgets/checkbox.html new file mode 100644 index 000000000..bbe201a29 --- /dev/null +++ b/netbox/templates/django/forms/widgets/checkbox.html @@ -0,0 +1,6 @@ +{% comment %} + Include a hidden field of the same name to ensure that unchecked checkboxes + are always included in the submitted form data. +{% endcomment %} + +{% include "django/forms/widgets/input.html" %}