Grid
The Grid question type presents users with a table where they can select one option per row.
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 row labels.
An array of strings representing the column labels (options for each row).
Whether the question is required.
Whether to randomize the order of rows.
Whether to randomize the order of columns.
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
table
headerRow
headerCell
rowWrapper
row
rowLabel
cell
radio
errorMessage
Data
Response Format
The Grid question type returns an object where keys are row labels and values are the selected column labels:
Validation
The Grid question validates that:
- All rows have a selected option when required is set to true.
- Any custom validation provided in the
customValidation
function passes.
If validation fails, it displays an error message listing the unanswered rows.
Advanced
Methods
The Grid question type inherits methods from the base Element class and includes some specific methods:
Set the response for the question.
Parameters:
value
(object): An object where keys are row labels and values are selected column labels
Validate the current response against the question’s rules.
Returns:
- An object with
isValid
(boolean) anderrorMessage
(string) properties.
Update the response based on the current state of the radio buttons.
This method is typically called internally when the user interacts with the question.
Example
Here’s an example of how to create a customized grid question: