Dependent Select

Cascading dropdown that reloads options when a parent field changes.

python 13 params

Preview

Usage

views.py
python
from djust import LiveView
from djust.components import DependentSelect


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = DependentSelect()
my_template.html
django
{{ component }}

Parameters

NameTypeDefaultDescription
namestr''Form field name.
parentstr''Name of the parent field this select depends on.
source_eventstr — renames the event''djust event to fire when parent changes.
labelstr''Optional label text.
placeholderstr'Select...'Placeholder text when nothing selected.
valuestr''Currently selected value.
optionslist | NoneNoneList of dicts with 'value'/'label' keys, or list of strings.
loadingboolFalseShow spinner while loading options.
disabledboolFalseWhether the select is disabled.
requiredboolFalseWhether the field is required.
errorstr''Error message to display.
custom_classstr''Additional CSS classes.
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.dependent_selectSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 2 of this component's classes at line 1440, 1441. Override those rules, or the custom properties they read, in a stylesheet loaded after it.