Text Input
The TextInput question type provides a single-line text input field for users to enter short text responses.
Basic Usage
Parameters
Unique identifier for the question.
The main question text.
Additional text to provide context or instructions.
Minimum required length of the response.
Maximum allowed length of the response.
Placeholder text for the input field.
Whether the question is required.
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
input
errorMessage
Data
Response Format
The TextInput question type returns a string containing the user’s text input:
Additional data stored includes:
responseLength
: The length of the response.
Validation
The TextInput question validates that:
- The response is not empty when required is true.
- The response length is at least minLength (if specified).
- The response length does not exceed maxLength (if specified).
- Any custom validation provided in the
customValidation
function passes.
If validation fails, it displays an appropriate error message.
Methods
The TextInput question type inherits methods from the base Element class and includes some specific methods:
Set the response for the question.
Parameters:
value
(string): The text response
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 text input question: