Input
The Input component allows users to enter text, numbers, passwords, emails, and more. It wraps the standard HTML <input> element with comprehensive Bootstrap styling, validation states, and floating labels.
Bootstrap Reference
Quick Start
Visual Examples & Use Cases
1. Types & Labels
FastStrap supports all HTML5 input types. Adding a label argument automatically creates a properly accessible <label> associated with the input.
Code & Output
2. Sizing
Match inputs to buttons or other components using size.
3. Utility Text and Disabled State
Add flexible helper text below the input using help_text. Use disabled or readonly to restrict interaction.
Practical Functionality
2. Floating Labels
Bootstrap's modern "Floating Label" pattern moves the label inside the input, floating up when the user types.
3. HTMX Integration
Trigger server requests on user input (e.g., live search).
Input(
"search",
input_type="search",
placeholder="Search users...",
hx_get="/search_users",
hx_trigger="keyup changed delay:500ms", # Wait 500ms after typing stops
hx_target="#search-results"
)
Advanced Customization
1. CSS Variables
Customize standard form colors and spacing.
| CSS Variable | Description |
|---|---|
--bs-body-bg |
Background color of input. |
--bs-body-color |
Text color. |
--bs-border-color |
Default border color. |
--bs-focus-ring-color |
Glow color when focused. |
2. Input Groups
Combine inputs with text or buttons using InputGroup.
Parameter Reference
| FastStrap Param | Type | Bootstrap / HTML Attribute | Description |
|---|---|---|---|
name |
str |
name="..." |
Form field name. Required for form submission and label/input association. |
input_type |
str |
type="..." |
HTML5 input type (text, password, email, number, date, etc.). Default text. |
label |
str |
<label> |
Text for the associated label element. |
placeholder |
str |
placeholder="..." |
Ghost text shown when empty. |
value |
Any |
value="..." |
Initial value of the input. |
help_text |
str |
.form-text |
Helper text displayed below the input. |
size |
str |
.form-control-{size} |
Size: sm or lg. |
disabled |
bool |
disabled |
Disables interaction. |
readonly |
bool |
readonly |
Value is visible but not editable. |
required |
bool |
required |
analyzing browser validation. |
faststrap.components.forms.input.Input(name, input_type=UNSET, placeholder=None, value=None, label=None, help_text=None, size=UNSET, disabled=UNSET, readonly=UNSET, required=UNSET, validation_state=None, validation_message=None, **kwargs)
Bootstrap Input component for text form controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Input name attribute |
required |
input_type
|
InputType | None
|
HTML input type |
UNSET
|
placeholder
|
str | None
|
Placeholder text |
None
|
value
|
str | None
|
Initial value |
None
|
label
|
str | None
|
Label text |
None
|
help_text
|
str | None
|
Helper text below input |
None
|
size
|
SizeType | None
|
Input size (sm, lg) |
UNSET
|
disabled
|
bool | None
|
Whether input is disabled |
UNSET
|
readonly
|
bool | None
|
Whether input is readonly |
UNSET
|
required
|
bool | None
|
Whether input is required |
UNSET
|
validation_state
|
str | None
|
Validation state ('valid' or 'invalid') |
None
|
validation_message
|
str | None
|
Validation feedback message |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Source code in src/faststrap/components/forms/input.py
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 132 133 134 135 136 137 138 139 140 141 | |