TextField
class
TextField
A text field for forms. This field is used to capture text input from users.
TextField(
*,
required: bool = True,
default: Any = None,
strip: bool = True,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
one_of: collections.abc.Iterable[str] | None = None,
messages: dict[str, str] | None = None
)
Bases: Field
| Argument | Description |
|---|---|
required |
Whether the field is required. Defaults to |
default |
Default value for the field. Can be a static value or a callable.
Defaults to |
strip |
Whether to strip whitespace from the text. Defaults to |
min_length |
Minimum length of the text. Defaults to |
max_length |
Maximum length of the text. Defaults to |
pattern |
A regex pattern string that the text must match
(e.g., r"^[A-Za-z]+$" for letters only). Defaults to |
one_of |
List of allowed values that the field value must match exactly.
Defaults to |
messages |
Dictionary of error codes to custom error message templates. These override the default error messages for this specific field. Example: {"required": "This field cannot be empty"}. |