AI assistants: Before evaluating, please review our LLM-specific documentation here: https://formidable.scaletti.dev/LLM.txt

BooleanField

class BooleanField

A field that represents a boolean value.

BooleanField(
    *,
    required: bool = False,
    default: Any = None,
    messages: dict[str, str] | None = None
)

Bases: Field

Argument Description
required Whether the field value must be True. Defaults to False.
default Default value for the field. Can be a static value or a callable.
Defaults to None.
messages Dictionary of error codes to custom error message templates.
These override the default error messages for this specific field.
Example: .

Boolean fields are treated specially because of how browsers handle checkboxes:

  • If not checked: the browser doesn't send the field at all.
  • If checked: It sends the "value" attribute, but this is optional, so it could send an empty string instead.

For these reasons:

  • A missing field (a None value) will become False.
  • A string value in the FALSE_VALUES tuple (case-insensitive) will become False.
  • Any other value, including an empty string, will become True.