DateRangePicker
Lightweight date range input with HTMX-friendly hooks.
Quick Start
Live Preview
Presets
DateRangePicker(
presets=[
("Last 7 days", "2026-03-10", "2026-03-17"),
("Last 30 days", "2026-02-16", "2026-03-17"),
],
)
Preset buttons populate the form inputs. If you also set auto=True, Faststrap submits the form after applying the preset.
HTMX Integration
DateRangePicker(
endpoint="/reports",
method="get",
auto=True,
hx_target="#results",
push_url=True,
)
Limits and Defaults
Use min_date, max_date, start_value, and end_value to control allowed ranges.
For method="post", ensure CSRF protection is enabled.
Preset shortcuts rely on the Faststrap runtime from add_bootstrap(app).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
start_name |
str |
"start_date" |
Start date field name. |
end_name |
str |
"end_date" |
End date field name. |
start_label |
str |
"Start date" |
Start date label. |
end_label |
str |
"End date" |
End date label. |
start_value |
str \| None |
None |
Initial start date in YYYY-MM-DD format. |
end_value |
str \| None |
None |
Initial end date in YYYY-MM-DD format. |
min_date |
str \| None |
None |
Earliest selectable date. |
max_date |
str \| None |
None |
Latest selectable date. |
presets |
list[tuple[str, str, str]] \| None |
None |
Preset buttons as (label, start, end). |
endpoint |
str \| None |
None |
Form action and optional HTMX endpoint. |
method |
"get" \| "post" |
"get" |
Submit method. |
auto |
bool |
False |
Submit on change when an endpoint exists. |
apply_label |
str \| None |
"Apply" |
Submit button label. Set None to hide. |
hx_target |
str \| None |
None |
HTMX target selector. |
hx_swap |
str \| None |
"outerHTML" |
HTMX swap style. |
push_url |
bool |
False |
Push URL for HTMX GET flows. |
form_cls / presets_cls / inputs_cls |
str \| None |
None |
Styling hooks. |
**kwargs |
Any |
Extra form attributes. |
API Reference
faststrap.components.forms.date_range_picker.DateRangePicker(*, start_name='start_date', end_name='end_date', start_label='Start date', end_label='End date', start_value=None, end_value=None, min_date=None, max_date=None, presets=None, endpoint=None, method='get', auto=False, apply_label='Apply', hx_target=None, hx_swap='outerHTML', push_url=False, form_cls=None, presets_cls=None, inputs_cls=None, **kwargs)
Date range picker with optional preset shortcuts.
Source code in src/faststrap/components/forms/date_range_picker.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |