Skip to content

Commit

Permalink
Preliminary work on 9583.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps committed Feb 7, 2024
1 parent e762755 commit f7294f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion netbox/templates/generic/object_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{% block content %}

{# Object list tab #}
<div class="tab-pane show active" id="object-list" role="tabpanel" aria-labelledby="object-list-tab" hx-include="#object-list thead select, #object-list input[type='search']">
<div class="tab-pane show active" id="object-list" role="tabpanel" aria-labelledby="object-list-tab">

{# Applied filters #}
{% if filter_form %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/inc/table_controls_htmx.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="col-auto d-print-none">
<div class="input-group input-group-flat me-2 quicksearch">
<input type="search" results="5" name="q" id="quicksearch" class="form-control px-2 py-1" placeholder="Quick search"
hx-get="{{ request.full_path }}" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
hx-get="" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
<span class="input-group-text py-1">
<a href="#" id="quicksearch_clear" class="d-none text-secondary"><i class="mdi mdi-close-circle"></i></a>
</span>
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/inc/table_header_filter_dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<i class="mdi mdi-filter-settings" style="font-size: 1.25rem;"> </i>
</a>
<div class="dropdown-menu dropdown-menu-end">
{% render_filter_field form_field %}
{% render_filter_field form_field table=table request=request %}
</div>
</div>
{% endif %}
16 changes: 14 additions & 2 deletions netbox/utilities/templatetags/form_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template


__all__ = (
'getfield',
'getfilterfield',
Expand All @@ -10,6 +11,7 @@
'widget_type',
)

from utilities.templatetags.helpers import querystring

register = template.Library()

Expand Down Expand Up @@ -68,13 +70,23 @@ def render_field(field, bulk_nullable=False, label=None):


@register.inclusion_tag('form_helpers/render_field.html')
def render_filter_field(field, bulk_nullable=False, label=None):
def render_filter_field(field, bulk_nullable=False, table=None, request=None):
"""
Render a single form field from template
"""
url = ""
kwargs = {
field.name: None
}
if request and table.htmx_url:
url = table.htmx_url + querystring(request, **kwargs)
elif request:
url = querystring(request, **kwargs)

if hasattr(field.field, 'widget'):
field.field.widget.attrs.update({
'hx-get': "",
'hx-get': url if url else '#',
'hx-push-url': "true",
'hx-target': '#object_list',
'hx-trigger': 'hidden.bs.dropdown from:closest .dropdown'
})
Expand Down

0 comments on commit f7294f7

Please sign in to comment.