3.6.4 Regression rendering hidden input for checkbox breaks forms.BooleanField in Filters #9744

Closed
opened 2025-12-29 21:21:58 +01:00 by adam · 5 comments
Owner

Originally created by @ibuclaw on GitHub (May 24, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.11

Steps to Reproduce

  1. Modify sources to add a forms.BooleanField parameter to a Filters form, e.g:
--- a/netbox/dcim/forms/filtersets.py
+++ b/netbox/dcim/forms/filtersets.py
@@ -162,11 +162,16 @@ class SiteFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte
     model = Site
     fieldsets = (
         FieldSet('q', 'filter_id', 'tag'),
+        FieldSet('boolean_field', name=_('Debug')),
         FieldSet('status', 'region_id', 'group_id', 'asn_id', name=_('Attributes')),
         FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
         FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')),
     )
     selector_fields = ('filter_id', 'q', 'region_id', 'group_id')
+    boolean_field = forms.BooleanField(
+        label=_('Test field'),
+        required=False
+    )
     status = forms.MultipleChoiceField(
         label=_('Status'),
         choices=SiteStatusChoices,
  1. Restart NetBox and visit the page (in this case /dcim/sites/ -> Filters
  2. Inspect generated html of the field.
<div class="form-check mb-0">
    <input type="hidden" name="boolean_field" value="">
    <input type="checkbox" name="boolean_field" id="id_boolean_field" class="form-check-input">
    <label for="id_boolean_field" class="form-check-label">Test field</label>
</div>

Expected Behavior

NetBox 3.7 rendered this as something like:

<div class="form-check">
    <input type="checkbox" name="boolean_field" class="form-check-input" placeholder="Test field" id="id_boolean_field">
    <label for="id_boolean_field" class="form-check-label">Test field</label>
</div>

Observed Behavior

There is a hidden input with the same name that did not exist in 3.7.x.

As far as I can tell, this means BooleanField's are ignored due to this GET event listener deleting all form data for it, because the "hidden" input has an empty value.
103c08c2d2/netbox/project-static/src/netbox.ts (L44-L47)

Originally created by @ibuclaw on GitHub (May 24, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.3 ### Python Version 3.11 ### Steps to Reproduce 1. Modify sources to add a `forms.BooleanField` parameter to a Filters form, e.g: ```diff --- a/netbox/dcim/forms/filtersets.py +++ b/netbox/dcim/forms/filtersets.py @@ -162,11 +162,16 @@ class SiteFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilte model = Site fieldsets = ( FieldSet('q', 'filter_id', 'tag'), + FieldSet('boolean_field', name=_('Debug')), FieldSet('status', 'region_id', 'group_id', 'asn_id', name=_('Attributes')), FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')), FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')), ) selector_fields = ('filter_id', 'q', 'region_id', 'group_id') + boolean_field = forms.BooleanField( + label=_('Test field'), + required=False + ) status = forms.MultipleChoiceField( label=_('Status'), choices=SiteStatusChoices, ``` 2. Restart NetBox and visit the page (in this case `/dcim/sites/` -> `Filters` 3. Inspect generated html of the field. ```html <div class="form-check mb-0"> <input type="hidden" name="boolean_field" value=""> <input type="checkbox" name="boolean_field" id="id_boolean_field" class="form-check-input"> <label for="id_boolean_field" class="form-check-label">Test field</label> </div> ``` ### Expected Behavior NetBox 3.7 rendered this as something like: ```html <div class="form-check"> <input type="checkbox" name="boolean_field" class="form-check-input" placeholder="Test field" id="id_boolean_field"> <label for="id_boolean_field" class="form-check-label">Test field</label> </div> ``` ### Observed Behavior There is a `hidden` input with the same name that did not exist in 3.7.x. As far as I can tell, this means `BooleanField`'s are ignored due to this GET event listener deleting all form data for it, because the "hidden" input has an empty value. https://github.com/netbox-community/netbox/blob/103c08c2d2bc3e32d8274b8d8ec8dd2380857388/netbox/project-static/src/netbox.ts#L44-L47
adam closed this issue 2025-12-29 21:21:58 +01:00
Author
Owner

@ibuclaw commented on GitHub (May 25, 2024):

I suspect it was introduced by a46255ddda

So I can't say why I'm not seeing this in 3.7.x then - maybe plug-ins pick up the upstream Django template, and not the Netbox vendored version, and now this is no longer the case in 4.x.

@ibuclaw commented on GitHub (May 25, 2024): I suspect it was introduced by https://github.com/netbox-community/netbox/commit/a46255ddda73e1e29c610d40aeb7054214014935 So I can't say why I'm not seeing this in 3.7.x then - maybe plug-ins pick up the upstream Django template, and not the Netbox vendored version, and now this is no longer the case in 4.x.
Author
Owner

@ibuclaw commented on GitHub (May 25, 2024):

Ah-ha! I don't see it in plug-ins as they are fudging the UI because of this bug.

https://github.com/netbox-community/netbox-topology-views/pull/408

@ibuclaw commented on GitHub (May 25, 2024): Ah-ha! I don't see it in plug-ins as they are fudging the UI _because_ of this bug. https://github.com/netbox-community/netbox-topology-views/pull/408
Author
Owner

@jeremystretch commented on GitHub (May 28, 2024):

Arbitrarily modifying core code does not constitute a valid bug report. Please modify your post above to describe the specific behavior in NetBox you believe is unintentional.

@jeremystretch commented on GitHub (May 28, 2024): Arbitrarily modifying core code does not constitute a valid bug report. Please modify your post above to describe the specific behavior in NetBox you believe is unintentional.
Author
Owner

@ibuclaw commented on GitHub (May 28, 2024):

It presents - in a bite-size example - code that already exists in plugins that "NetBox Cloud and NetBox Enterprise include commercial support for..." are doing, and NetBox is breaking them by injecting bad html for this field type.

There already one hacky condition in the template because some other part of NetBox got broke by it.

eb3adc050d/netbox/templates/django/forms/widgets/checkbox.html (L6)

{% if widget.name != '_selected_action' %}

If this was instead something along the lines of

{% if htmx_enabled %}

Then that would resolve the issue - if I correctly understand the original intention for introducing this hidden input field.

@ibuclaw commented on GitHub (May 28, 2024): It presents - in a bite-size example - code that already exists in plugins that "NetBox Cloud and NetBox Enterprise include commercial support for..." are doing, and NetBox is breaking them by injecting bad html for this field type. There already one hacky condition in the template because some other part of NetBox got broke by it. https://github.com/netbox-community/netbox/blob/eb3adc050dfa6ff93dfc9c6c8965906371f85f7b/netbox/templates/django/forms/widgets/checkbox.html#L6 ``` {% if widget.name != '_selected_action' %} ``` If this was instead something along the lines of ``` {% if htmx_enabled %} ``` Then that would resolve the issue - if I correctly understand the original intention for introducing this hidden input field.
Author
Owner

@jeremystretch commented on GitHub (Jun 3, 2024):

@ibuclaw the code you reference was added intentionally and serves a purpose. If you would like to propose an alternative solution, please submit a feature request citing the detailed proposal and justification for the change.

I'm closing this issue as it does not identify unexpected, reproducible behavior in NetBox itself.

@jeremystretch commented on GitHub (Jun 3, 2024): @ibuclaw the code you reference was added intentionally and serves a purpose. If you would like to propose an alternative solution, please submit a [feature request](https://github.com/netbox-community/netbox/issues/new?assignees=&labels=type%3A+feature%2Cstatus%3A+needs+triage&projects=&template=feature_request.yaml) citing the detailed proposal and justification for the change. I'm closing this issue as it does not identify unexpected, reproducible behavior in NetBox itself.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9744