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

ArgumentDescription
required

Whether the field is required. Defaults to True.

default

Default value for the field. Can be a static value or a callable. Defaults to None.

strip

Whether to strip whitespace from the text. Defaults to True.

min_length

Minimum length of the text. Defaults to None (no minimum).

max_length

Maximum length of the text. Defaults to None (no maximum).

pattern

A regex pattern string that the text must match (e.g., r"^[A-Za-z]+$" for letters only). Defaults to None.

one_of

List of allowed values that the field value must match exactly. Defaults to None.

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"}.