Select
The Select component creates dropdown selection menus with full Bootstrap styling, validation support, and HTMX integration.
Quick Start
Select("country", ("us", "United States"), ("uk", "United Kingdom"), ("ca", "Canada"), ("au", "Australia"), label="Country")
Usage Scenarios
Sizes
Select("priority", ("high", "High"), ("medium", "Medium"), label="Priority Level", size="lg")
Select("category", ("tech", "Technology"), ("design", "Design"), label="Category")
Select("status", ("active", "Active"), ("inactive", "Inactive"), label="Status", size="sm")
Multiple Selection
Select("skills", ("python", "Python"), ("javascript", "JavaScript"), ("html", "HTML/CSS"), ("sql", "SQL"), ("docker", "Docker"), label="Skills", help_text="Hold Ctrl/Cmd to select multiple", multiple=True)
Pre-selected Options
Select("theme", ("light", "Light Mode"), ("dark", "Dark Mode", True), ("auto", "Auto (System)"), label="Theme Preference")
Validation States
Parameter Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
Required | Form field name attribute |
*options |
tuple |
Required | Options as (value, label) or (value, label, selected) |
label |
str \| None |
None |
Label text above select |
help_text |
str \| None |
None |
Helper text below select |
size |
"sm" \| "lg" \| None |
None |
Select size (default is medium) |
disabled |
bool \| None |
None |
Whether select is disabled |
required |
bool \| None |
None |
Whether select is required |
multiple |
bool \| None |
None |
Allow multiple selections |
cls |
str |
"" |
Additional CSS classes |
**kwargs |
Any |
- | Additional HTML attributes (id, hx-, data-, aria-*) |
Accessibility
- Labels are linked to selects via
forandidattributes. - Required fields are marked with
requiredattribute and a red asterisk in the label. - Help text is linked via
aria-describedby.
API Reference
faststrap.components.forms.select.Select(name, *options, label=None, help_text=None, size=UNSET, disabled=UNSET, required=UNSET, multiple=UNSET, **kwargs)
Bootstrap Select component for dropdown selections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Select name attribute |
required |
*options
|
tuple[str, str] | tuple[str, str, bool]
|
Options as (value, label) or (value, label, selected) |
()
|
label
|
str | None
|
Label text |
None
|
help_text
|
str | None
|
Helper text below select |
None
|
size
|
SizeType | None
|
Select size (sm, lg) |
UNSET
|
disabled
|
bool | None
|
Whether select is disabled |
UNSET
|
required
|
bool | None
|
Whether select is required |
UNSET
|
multiple
|
bool | None
|
Allow multiple selections |
UNSET
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Source code in src/faststrap/components/forms/select.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |