Check Box
The CheckBox component provides a single checkbox for collecting binary (yes/no, true/false, agree/disagree) responses from users.
Basic Usage
Parameters
Unique identifier for the checkbox.
The label text for the checkbox.
Whether the checkbox must be checked.
A custom validation function that takes the response as input and returns true if valid, or an error message string if invalid.
Custom styles to apply to the checkbox. Available keys are:
root
innerContainer
checkboxFlexContainer
checkbox
checkboxLabel
errorMessage
Data
Response Format
The CheckBox component returns a boolean value:
Validation
The CheckBox component validates that:
- The checkbox is checked when required is true.
- Any custom validation provided in the
customValidation
function passes.
If validation fails, it displays an error message.
Advanced
Methods
The CheckBox component inherits methods from the base Element class and includes some specific methods:
Set the response for the checkbox.
Parameters:
value
(boolean): The checked state of the checkbox
Validate the current response against the checkbox’s rules.
Returns:
- An object with
isValid
(boolean) anderrorMessage
(string) properties.
Example
Here’s an example of how to create a more customized checkbox:
This example demonstrates how to use custom styling and validation to create a more tailored checkbox component.