Single Select
The SingleSelect question type presents users with a list of options from which they can select one answer.
Basic Usage
Parameters
Unique identifier for the question.
The main question text.
Additional text to provide context or instructions.
An array of strings representing the available options.
Whether the question is required.
Whether to randomize the order of options.
Whether to include an “Other” option with a text input.
The label for the “Other” option, if allowed.
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 question. Available keys are:
root
innerContainer
textContainer
text
subText
optionsContainer
option
radio
label
otherInput
errorMessage
Data
Response Format
The SingleSelect question type returns a string representing the selected option:
If the “Other” option is selected and filled:
Validation
The SingleSelect question validates that:
- An option has been selected when required is set to true.
- If “Other” is selected, the other input is not empty when required is true.
- The selected option is valid (exists in the options array or is “other”).
- Any custom validation provided in the
customValidation
function passes.
If validation fails, it displays an appropriate error message.
Methods
The SingleSelect question type inherits methods from the base Element class and includes some specific methods:
Set the response for the question.
Parameters:
value
(string or object): The selected option or other value
Validate the current response against the question’s rules.
Returns:
- An object with
isValid
(boolean) anderrorMessage
(string) properties.
Example
Here’s an example of how to create a customized single-select question: