Skip to content

Commit e65b2a9

Browse files
committed
Closes #11625: Add HTMX support to ObjectEditView
1 parent 7accdd5 commit e65b2a9

File tree

4 files changed

+65
-54
lines changed

4 files changed

+65
-54
lines changed

docs/release-notes/version-3.5.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
### Enhancements
66

7-
* [#11517](https://github.com/netbox-community/netbox/issues/11517) - Standardize the inclusion of related objects across the entire UI
8-
* [#11584](https://github.com/netbox-community/netbox/issues/11584) - Add a list view for contact assignments
97
* [#11254](https://github.com/netbox-community/netbox/issues/11254) - Introduce the `X-Request-ID` HTTP header to annotate the unique ID of each request for change logging
108
* [#11440](https://github.com/netbox-community/netbox/issues/11440) - Add an `enabled` field for device type interfaces
9+
* [#11517](https://github.com/netbox-community/netbox/issues/11517) - Standardize the inclusion of related objects across the entire UI
10+
* [#11584](https://github.com/netbox-community/netbox/issues/11584) - Add a list view for contact assignments
11+
* [#11625](https://github.com/netbox-community/netbox/issues/11625) - Add HTMX support to ObjectEditView
1112

1213
### Other Changes
1314

netbox/netbox/views/generic/object_views.py

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def get(self, request, *args, **kwargs):
218218
form = self.form(instance=obj, initial=initial_data)
219219
restrict_form_fields(form, request.user)
220220

221+
# If this is an HTMX request, return only the rendered form HTML
222+
if is_htmx(request):
223+
return render(request, 'htmx/form.html', {
224+
'form': form,
225+
})
226+
221227
return render(request, self.template_name, {
222228
'model': model,
223229
'object': obj,

netbox/templates/generic/object_edit.html

+5-52
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{% extends 'base/layout.html' %}
2-
{% load form_helpers %}
3-
{% load helpers %}
42

53
{% comment %}
64
Blocks:
@@ -48,56 +46,11 @@
4846
<form action="" method="post" enctype="multipart/form-data" class="form-object-edit mt-5">
4947
{% csrf_token %}
5048

51-
{% block form %}
52-
{% if form.fieldsets %}
53-
54-
{# Render hidden fields #}
55-
{% for field in form.hidden_fields %}
56-
{{ field }}
57-
{% endfor %}
58-
59-
{# Render grouped fields according to Form #}
60-
{% for group, fields in form.fieldsets %}
61-
<div class="field-group mb-5">
62-
{% if group %}
63-
<div class="row mb-2">
64-
<h5 class="offset-sm-3">{{ group }}</h5>
65-
</div>
66-
{% endif %}
67-
{% for name in fields %}
68-
{% with field=form|getfield:name %}
69-
{% if not field.field.widget.is_hidden %}
70-
{% render_field field %}
71-
{% endif %}
72-
{% endwith %}
73-
{% endfor %}
74-
</div>
75-
{% endfor %}
76-
77-
{% if form.custom_fields %}
78-
<div class="field-group mb-5">
79-
<div class="row mb-2">
80-
<h5 class="offset-sm-3">Custom Fields</h5>
81-
</div>
82-
{% render_custom_fields form %}
83-
</div>
84-
{% endif %}
85-
86-
{% if form.comments %}
87-
<div class="field-group mb-5">
88-
<h5 class="text-center">Comments</h5>
89-
{% render_field form.comments %}
90-
</div>
91-
{% endif %}
92-
93-
{% else %}
94-
{# Render all fields in a single group #}
95-
<div class="field-group mb-5">
96-
{% render_form form %}
97-
</div>
98-
{% endif %}
99-
100-
{% endblock form %}
49+
<div id="form_fields">
50+
{% block form %}
51+
{% include 'htmx/form.html' %}
52+
{% endblock form %}
53+
</div>
10154

10255
<div class="text-end my-3">
10356
{% block buttons %}

netbox/templates/htmx/form.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{% load form_helpers %}
2+
3+
{% if form.fieldsets %}
4+
5+
{# Render hidden fields #}
6+
{% for field in form.hidden_fields %}
7+
{{ field }}
8+
{% endfor %}
9+
10+
{# Render grouped fields according to Form #}
11+
{% for group, fields in form.fieldsets %}
12+
<div class="field-group mb-5">
13+
{% if group %}
14+
<div class="row mb-2">
15+
<h5 class="offset-sm-3">{{ group }}</h5>
16+
</div>
17+
{% endif %}
18+
{% for name in fields %}
19+
{% with field=form|getfield:name %}
20+
{% if not field.field.widget.is_hidden %}
21+
{% render_field field %}
22+
{% endif %}
23+
{% endwith %}
24+
{% endfor %}
25+
</div>
26+
{% endfor %}
27+
28+
{% if form.custom_fields %}
29+
<div class="field-group mb-5">
30+
<div class="row mb-2">
31+
<h5 class="offset-sm-3">Custom Fields</h5>
32+
</div>
33+
{% render_custom_fields form %}
34+
</div>
35+
{% endif %}
36+
37+
{% if form.comments %}
38+
<div class="field-group mb-5">
39+
<h5 class="text-center">Comments</h5>
40+
{% render_field form.comments %}
41+
</div>
42+
{% endif %}
43+
44+
{% else %}
45+
46+
{# Render all fields in a single group #}
47+
<div class="field-group mb-5">
48+
{% render_form form %}
49+
</div>
50+
51+
{% endif %}

0 commit comments

Comments
 (0)