Multi Select
Multi-select checkbox list component.
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
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | '' | form field name |
| label | str | '' | label text |
| options | list | None | None | list of dicts with keys: value, label |
| selected | list | None | None | list of currently selected values |
| event | str — 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 |
| placeholder | str | 'Search...' | — |
| custom_class | str | '' | — |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.multi_select | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 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. |
| css | djust_theming/components.css | Defines 1 of this component's classes at line 1453. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/scaffold.css | Defines 1 of this component's classes at line 445. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |