Combobox
Searchable select (combobox) component.
Preview
Python
Rust
Go
Arguments
combobox(name='language', event='set_language', label='Language', value='python', options=[{'value': 'python', 'label': 'Python'}, {'value': 'rust', 'label': 'Rust'}, {'value': 'go', 'label': 'Go'}])Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import Combobox
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = Combobox(name='language', event='set_language', label='Language', value='python', options=[{'value': 'python', 'label': 'Python'}, {'value': 'rust', 'label': 'Rust'}, {'value': 'go', 'label': 'Go'}])
@event_handler()
def language_search(self, **kwargs):
pass # your app acts on 'language_search'; no component state moves
@event_handler()
def set_language(self, value, **kwargs):
self.component.value = valuemy_template.html
django
{{ component }}Events this component sends to the view: language_search, set_language.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | '' | form field name |
| label | str | '' | label text |
| value | str | '' | currently selected value |
| options | list | None | None | list of dicts with keys: value, label |
| event | str — renames the event | '' | dj-change event name |
| search_event | str — renames the event | '' | dj-input event for search |
| placeholder | str | 'Search...' | search input placeholder |
| 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.combobox | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 481, 523, 525, 779, 780, 781, 783. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/scaffold.css | Defines 3 of this component's classes at line 418, 438, 445. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/components.css | Defines 2 of this component's classes at line 1114, 1453. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |