ListField
class
ListField
A field that represents a list of same-type values.
ListField(
type: Any = None,
*,
strict: bool = False,
required: bool = True,
default: Any = None,
min_items: int | None = None,
max_items: int | None = None,
one_of: collections.abc.Iterable[typing.Any] | None = None,
messages: dict[str, str] | None = None
)
Bases: Field
| Argument | Description |
|---|---|
type |
A callable that is used to cast the items in the list. Defaults to |
strict |
Whether to enforce strict type checking. Defaults to |
required |
Whether the field is required. Defaults to |
default |
Default value for the field. Can be a static value or a callable.
Defaults to |
min_items |
Minimum number of items in the list. Defaults to None (no minimum). |
max_items |
Maximum number of items in the list. Defaults to None (no maximum). |
one_of |
List of values that the field value must be one of. 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"}. |
This is the field to use when you expect multiple values for a single field, like
a <select multiple> HTML input or a group of checkboxes with the same name.
A type is a function used to cast the items in the list. It can be a simple Python
type like int or it can be your own function.
If strict is True, any casting error will raise an exception. If strict is
False (the default), the error will be ignored and the value will not be added
to the final list.