Resources
Examples
Let’s walk through creating a more complex survey using RoundtableJS. This example will demonstrate how to set up a survey with multiple pages, apply custom styling, and include various question types.
Step 1: Import Necessary Modules
First, import the Survey
class and the question types you’ll use:
Step 2: Create the Survey Instance
Define a function to create the survey instance with custom styles:
Step 3: Create Survey Pages
Define functions to create the survey pages. Each page will contain different question types.
Step 4: Run the Survey
Create an asynchronous function to handle the survey flow, display pages, and finish the survey.
Explanation
- Import Modules: Import the necessary classes and question types from
roundtable-js
. - Create Survey Instance: The
createSurvey
function initializes a new survey with custom styles applied to the body, container, and buttons. - Create Pages: The
createPage1
andcreatePage2
functions define two pages of the survey. Page 1 collects demographic information, and Page 2 collects user feedback. - Run the Survey: The
runSurvey
function handles the survey flow. It displays each page sequentially, retrieves responses, and completes the survey with a thank you message.
Customization
You can extend this example indefinitely. Here are some ideas:
- Additional Pages: Create more pages with various question types like
MultiSelect
,Grid
, etc. - Conditional Logic: Add conditional logic to show or hide questions based on previous answers.
- Advanced Styling: Customize the survey further by defining more detailed styles for individual questions or error messages.