Linked selects¶
Linked-select support is optional and uses registered django-ajax-selects
lookups to populate a django.forms.Select through HTMX.
URL configuration¶
Include the package URLs under the htmx_views namespace:
from django.urls import include, path
urlpatterns = [
path(
"htmx-views/",
include(("htmx_views.urls", "htmx_views"), namespace="htmx_views"),
),
]
Widget usage¶
Use htmx_views.widgets.HTMXSelectWidget with a registered lookup:
from django import forms
from htmx_views.widgets import HTMXSelectWidget
class EquipmentForm(forms.Form):
module = forms.ModelChoiceField(queryset=...)
category = forms.ModelChoiceField(
queryset=...,
widget=HTMXSelectWidget("categories", parent="module"),
)
If parent is omitted, the widget uses the lookup’s parameter_name.
The endpoint passes the selected parent value to the lookup and renders the
returned objects as escaped <option> elements.