Survey Constructor
The Survey constructor is your starting point for creating a new survey in RoundtableJS.
Basic Usage
The Survey constructor accepts a single optional parameter that stores any metadata and custom styles.
customSurveyDetails
An object containing custom details and styles for the survey.
Example Custom Survey Details
participantId
(string): A unique identifier for the survey participant.condition
(string): The experimental condition or group for the survey.styles
(object): Custom styles to be applied globally to the survey.
Styling
The Survey constructor allows you to define global styles that will be applied to the entire survey. There are two main categories of styles you can set:
- Survey-level styles: Applied to the overall survey structure.
- Element-level styles: Applied to all elements within the survey.
Survey-level Styling
These styles are applied to the overall survey structure:
Element-level Styling
You can also define styles that will be applied to all elements within the survey:
These styles will be applied to all elements in the survey, but can be overridden by individual element styles.
Available Style Keys
Survey-level style keys:
body
: Styles for the survey bodycontainer
: Styles for the main survey containernavigation
: Styles for the navigation containerbutton
: Styles for survey navigation buttonserrorMessage
: Styles for error messagesnextButtonError
: Styles for the error message next to the ‘Next’ buttonfinishMessage
: Styles for the survey completion message
Element-level style keys:
root
: Styles for the main container of each elementinnerContainer
: Styles for the inner container of elements (if applicable)textContainer
: Styles for the container holding text elementstext
: Styles for the main text (usually the question text)subText
: Styles for additional instructional texterrorMessage
: Styles for validation error messages
For details on the styling syntax and more advanced styling options that RoundtableJS follows, consult our Styling page.
Methods
setSurveyDetail(key, value)
Set a custom survey detail.
- Parameters:
key
(string): The key for the survey detailvalue
(any): The value to set for the survey detail
getSurveyDetail(key)
Retrieve a custom survey detail.
- Parameters:
key
(string): The key of the survey detail to retrieve
- Returns:
- The value of the specified survey detail
showPage(page)
Display a specific page of the survey.
- Parameters:
page
(object): The page object to display
- Returns:
- A Promise that resolves when the page is completed
finishSurvey(options)
Complete the survey and display a finishing message.
- Parameters:
options
(object): An object containing the finishing optionsmessage
(string): The message to display upon survey completion
getResponse(questionId)
Retrieve the most recent response for a specific question.
- Parameters:
questionId
(string): The ID of the question
- Returns:
- The most recent response for the specified question, or null if not found
getAllResponses()
Retrieve all responses collected in the survey.
- Returns:
- An array of all response objects
getAllSurveyData()
Retrieve all survey data, including survey details and responses.
- Returns:
- An object containing surveyDetails and responses
addPlugin(plugin)
Add a plugin to the survey.
- Parameters:
plugin
(object): The plugin object to add
removePlugin(plugin)
Remove a plugin from the survey.
- Parameters:
plugin
(object): The plugin object to remove
- Returns:
true
if the plugin was successfully removed,false
otherwise