Boolean Field Type
Description:
The boolean
field type is used to capture true/false values from users. It provides a simple way to collect binary choices, preferences, or flags. This field type ensures that boolean data is captured consistently and can be used for conditional logic, filtering, and decision-making within your application.
Elasticsearch Mapping: boolean
YAML Definition
- name: is_active
type: boolean
display_name: "Active Status"
guidance: "Check if this item is active."
required: false
readonly: false
hidden: false
default_value: false
display: "checkbox"
Attributes
-
name (string): Required.
The unique identifier for the field. -
type (string): Required.
Must be set toboolean
for boolean fields. -
display_name (string): Optional.
The label displayed in the user interface. If not provided, a formatted version ofname
is used. -
guidance (string): Optional.
Help text or instructions for the field, assisting users in understanding what the boolean choice represents. -
required (boolean): Optional.
Iftrue
, the field must be filled before submission. Default:false
. -
readonly (boolean): Optional.
Iftrue
, the field is read-only and cannot be edited by the user. Default:false
. -
hidden (boolean): Optional.
Iftrue
, the field is hidden from the user interface. Default:false
. -
default_value (boolean): Optional.
The default boolean value displayed when the form is first loaded. Default:false
. -
display (string): Optional.
UI display type. Options:checkbox
,radio
. Default:checkbox
.
Examples
Basic Boolean Field:
- name: is_active
type: boolean
display_name: "Active Status"
guidance: "Check if this item is active"
default_value: true
Required Boolean Field:
- name: terms_accepted
type: boolean
display_name: "Accept Terms and Conditions"
guidance: "You must accept the terms to continue"
required: true
display: "checkbox"
Radio Button Boolean:
- name: newsletter_subscription
type: boolean
display_name: "Subscribe to Newsletter"
guidance: "Would you like to receive our newsletter?"
display: "radio"
default_value: false
Readonly Boolean Field:
- name: system_enabled
type: boolean
display_name: "System Status"
readonly: true
default_value: true
Usage Notes
- Display Options:
- checkbox: Standard checkbox input (default)
- radio: Radio button selection with Yes/No options
- Default Values:
- Use
default_value
to set the initial state of the boolean field. - Common defaults include
true
for active status fields andfalse
for opt-in fields.
- Use
- Required Fields:
- When
required
istrue
, users must explicitly make a choice. - Useful for terms acceptance, consent forms, or critical decisions.
- When
- Readonly Fields:
- Use
readonly
for system-managed boolean flags. - Common for status indicators that are controlled by the system.
- Use
- Hidden Fields:
- Use
hidden
for boolean flags that are managed programmatically. - Useful for internal flags that don’t need user interaction.
- Use
- Validation:
- Boolean fields typically don’t require complex validation.
- The main validation is ensuring required fields are answered.
- Use Cases:
- Status Flags: Active/inactive, enabled/disabled, published/draft.
- Preferences: Newsletter subscriptions, notifications, privacy settings.
- Consent: Terms acceptance, privacy policy agreement, marketing consent.
- Feature Toggles: Enable/disable features, show/hide sections.
- Workflow States: Completed/pending, approved/rejected, verified/unverified.
- User Experience:
- Provide clear
display_name
andguidance
to explain what the boolean choice means. - Use positive language in labels to avoid confusion.
- Consider the context when choosing between checkbox and radio display.
- Provide clear
- Data Processing:
- Boolean values are stored as
true
orfalse
. - Can be easily used in conditional logic and filtering.
- Efficient for database queries and indexing.
- Boolean values are stored as
- Accessibility:
- Ensure that boolean fields are keyboard accessible.
- Provide clear labels that screen readers can interpret.
- Consider providing additional context for complex boolean decisions.
By incorporating the boolean
field type into your schema, you provide users with a simple and intuitive way to make binary choices, enhancing the usability and data integrity of your application.