Multi Select

Multi-select checkbox list component.

python 8 params

Preview

Arguments
multi_select(name='frameworks', label='Frameworks', options=[{'value': 'django', 'label': 'Django'}, {'value': 'flask', 'label': 'Flask'}, {'value': 'fastapi', 'label': 'FastAPI'}], selected=['django'], event='set_frameworks')

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import MultiSelect


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

    def mount(self, request, **kwargs):
        self.component = MultiSelect(name='frameworks', label='Frameworks', options=[{'value': 'django', 'label': 'Django'}, {'value': 'flask', 'label': 'Flask'}, {'value': 'fastapi', 'label': 'FastAPI'}], selected=['django'], event='set_frameworks')

    @event_handler()
    def set_frameworks(self, value, **kwargs):
        self.component.selected = ...  # the handler gets `option` (the box) and `value` (ticked or not)
my_template.html
django
{{ component }}

Events this component sends to the view: set_frameworks.

Parameters

NameTypeDefaultDescription
namestr''form field name
labelstr''label text
optionslist | NoneNonelist of dicts with keys: value, label
selectedlist | NoneNonelist of currently selected values
eventstr — renames the event''dj-change event name. Each box sends ``option`` (its value) and ``value`` (whether it is now ticked):: @event_handler() def set_frameworks(self, option, value, **kwargs): picked = [s for s in self.picker.selected if s != option] self.picker.selected = picked + [option] if value else picked
placeholderstr'Search...'—
custom_classstr''—
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.multi_selectSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 5 of this component's classes at line 525, 960, 965, 967, 968. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/components.cssDefines 1 of this component's classes at line 1453. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/scaffold.cssDefines 1 of this component's classes at line 445. Override those rules, or the custom properties they read, in a stylesheet loaded after it.