Просмотр исходного кода

Fixes #13064: Ensure unchecked checkboxes do not revert to original values upon HTMX form refresh

Jeremy Stretch 2 лет назад
Родитель
Сommit
a46255ddda
2 измененных файлов с 10 добавлено и 0 удалено
  1. 4 0
      netbox/netbox/settings.py
  2. 6 0
      netbox/templates/django/forms/widgets/checkbox.html

+ 4 - 0
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]

+ 6 - 0
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 %}
+<input type="hidden" name="{{ widget.name }}" value="">
+{% include "django/forms/widgets/input.html" %}