Leverage HTMX to simplify rendering of complex form fields #7711

Closed
opened 2025-12-29 20:27:21 +01:00 by adam · 10 comments
Owner

Originally created by @jeremystretch on GitHub (Mar 2, 2023).

NetBox version

v3.4.5

Feature type

Change to existing functionality

Proposed functionality

#11625 introduced the ability to dynamically render object edit forms in response to changing field selections. We can leverage this new ability to simplify forms which have fields that can reference different types of related objects.

For example, the circuit termination edit form allows the user to select either a site or a provider network as the "attached" object:

Screenshot 2023-03-02 at 13-34-09 Editing circuit termination 1002840283 Termination Z NetBox

When the "site" tab is selected, the three relevant fields (region, group, and site) are displayed. When the "provider network" tab is selected, these are replaced with two different fields (provider and provider network). All five of these fields are declared on the form, and the values of all five are sent when the form is submitted. This can be confusing to the user, especially when field validation error messages end up on a hidden tab (as in #11816, for instance).

We can change the tabs to a dropdown selection field that triggers the form to re-render automatically in response to the related object type changing, and return only the relevant fields.

Use case

This change will simplify the appearance of forms within the UI, obviating the need to hide some fields behind tabs. It will also eliminate the need for many of our custom form templates.

Database changes

No response

External dependencies

No response

Originally created by @jeremystretch on GitHub (Mar 2, 2023). ### NetBox version v3.4.5 ### Feature type Change to existing functionality ### Proposed functionality #11625 introduced the ability to dynamically render object edit forms in response to changing field selections. We can leverage this new ability to simplify forms which have fields that can reference different types of related objects. For example, the circuit termination edit form allows the user to select either a site or a provider network as the "attached" object: ![Screenshot 2023-03-02 at 13-34-09 Editing circuit termination 1002840283 Termination Z NetBox](https://user-images.githubusercontent.com/13487278/222520428-6d0f8a98-f6da-4b7e-abd6-de4bf1635c03.png) When the "site" tab is selected, the three relevant fields (region, group, and site) are displayed. When the "provider network" tab is selected, these are replaced with two different fields (provider and provider network). All five of these fields are declared on the form, and the values of all five are sent when the form is submitted. This can be confusing to the user, especially when field validation error messages end up on a hidden tab (as in #11816, for instance). We can change the tabs to a dropdown selection field that triggers the form to re-render automatically in response to the related object type changing, and return only the relevant fields. ### Use case This change will simplify the appearance of forms within the UI, obviating the need to hide some fields behind tabs. It will also eliminate the need for many of our custom form templates. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:27:21 +01:00
adam closed this issue 2025-12-29 20:27:21 +01:00
Author
Owner

@dhenschen commented on GitHub (May 9, 2023):

I would like to take ownership of this issue please.

@dhenschen commented on GitHub (May 9, 2023): I would like to take ownership of this issue please.
Author
Owner

@arthanson commented on GitHub (May 9, 2023):

@dhenschen I'm working on something related to this for cabling, so let me know any progress you get on this and I will let you know what I come up with.

@arthanson commented on GitHub (May 9, 2023): @dhenschen I'm working on something related to this for cabling, so let me know any progress you get on this and I will let you know what I come up with.
Author
Owner

@dhenschen commented on GitHub (May 19, 2023):

@arthanson, Are these the HTMX changes you were referencing: https://github.com/netbox-community/netbox/pull/12491

@dhenschen commented on GitHub (May 19, 2023): @arthanson, Are these the HTMX changes you were referencing: https://github.com/netbox-community/netbox/pull/12491
Author
Owner

@arthanson commented on GitHub (May 19, 2023):

@dhenschen not that one, it was for cable terminations - I am still working on it in the background so no PR yet.

@arthanson commented on GitHub (May 19, 2023): @dhenschen not that one, it was for cable terminations - I am still working on it in the background so no PR yet.
Author
Owner

@dhenschen commented on GitHub (May 22, 2023):

@jeremystretch, I've identified the following templates that follow the same pattern as circuit termination and could potentially benefit from HTMX improvements:

  • circuittermination_edit.html
  • inventoryitem_edit.html
  • l2vpntermination_edit.html
  • service_edit.html
  • vlan_edit.html
  • ipaddress_edit.html
  • Adding a custom field

To clarify the scope of this issue, would you like all forms that follow the same model as circuit termination to be updated as part of this issue? If so, would you prefer separate pull requests for each form to facilitate the review process?

@dhenschen commented on GitHub (May 22, 2023): @jeremystretch, I've identified the following templates that follow the same pattern as circuit termination and could potentially benefit from HTMX improvements: - [ ] circuittermination_edit.html - [ ] inventoryitem_edit.html - [ ] l2vpntermination_edit.html - [ ] service_edit.html - [ ] vlan_edit.html - [ ] ipaddress_edit.html - [ ] Adding a custom field To clarify the scope of this issue, would you like all forms that follow the same model as circuit termination to be updated as part of this issue? If so, would you prefer separate pull requests for each form to facilitate the review process?
Author
Owner

@dhenschen commented on GitHub (May 22, 2023):

@arthanson, I've made progress on this issue and created a pull request at https://github.com/netbox-community/netbox/pull/12675.

Regarding the implementation, I'm considering adding another database field to facilitate this UI change. It appears to be the cleanest approach so far, and it may enable us to perform additional validation on this and similar forms if desired. I would appreciate your input and guidance on whether this approach aligns with our objectives.

Please review the pull request and let me know your thoughts.

@dhenschen commented on GitHub (May 22, 2023): @arthanson, I've made progress on this issue and created a pull request at https://github.com/netbox-community/netbox/pull/12675. Regarding the implementation, I'm considering adding another database field to facilitate this UI change. It appears to be the cleanest approach so far, and it may enable us to perform additional validation on this and similar forms if desired. I would appreciate your input and guidance on whether this approach aligns with our objectives. Please review the pull request and let me know your thoughts.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 10, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Nov 10, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Dec 10, 2023):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Dec 10, 2023): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Author
Owner

@DanSheps commented on GitHub (Dec 13, 2023):

Re-opening this as I believe it was closed in error. @jeremystretch do we still want to move forward with this?

@DanSheps commented on GitHub (Dec 13, 2023): Re-opening this as I believe it was closed in error. @jeremystretch do we still want to move forward with this?
Author
Owner

@jeremystretch commented on GitHub (Dec 13, 2023):

No; it's too broad. We'll need to open more detailed FRs scoping specific work to move this initiative forward.

@jeremystretch commented on GitHub (Dec 13, 2023): No; it's too broad. We'll need to open more detailed FRs scoping specific work to move this initiative forward.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7711