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.
Quick Start
Usage Scenarios
Types & Labels
Input("email", input_type="email", label="Email Address", placeholder="name@example.com")
Input("password", input_type="password", label="Password")
Sizing
Input("large_input", placeholder="Large Input", size="lg")
Input("default_input", placeholder="Default Input")
Input("small_input", placeholder="Small Input", size="sm")
Help Text and Disabled State
Input("username", label="Username", help_text="Must be 8-20 characters long.", disabled=True, value="jdoe_archived")
Validation States
Input("username", validation_state="valid", value="Correct!")
Input("username", validation_state="invalid", value="Invalid data")
Floating Labels
HTMX Integration
Input("search", input_type="search", placeholder="Search users...", hx_get="/search_users", hx_trigger="keyup changed delay:500ms", hx_target="#search-results")
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 |
Marks field as required for browser validation. |
validation_state |
str |
.is-valid / .is-invalid |
Validation state: valid or invalid. |
validation_message |
str |
.valid-feedback / .invalid-feedback |
Feedback message shown for validation state. |
Accessibility
- Labels are automatically associated with inputs via
forandidattributes. - Required fields display a red asterisk.
- Help text is linked via
aria-describedby. - Floating labels use proper
for/idassociations.
API Reference
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 | |