---
title: Nest Content Within Choice Options
product: Survey Creator
description: Create dynamic nesting choice options in Checkboxes and Radio Button Group questions. When a respondent selects a specific choice, follow-up sub-questions appear automatically cascading from that option. View our free JavaScript demo to learn more.
framework: React
source: https://surveyjs.io/survey-creator/examples/nest-sub-questions-within-choice-options/reactjs
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Nest Content Within Choice Options (React)

Survey authors can insert questions and panels inside individual choice options in Checkboxes and Radio Button Group questions. These nested elements appear dynamically when respondents select the corresponding option. To add a nested question or panel, click the button on the right side of a choice option on the design surface.

To enable this feature in Survey Creator, set the [`maxChoiceContentNestingLevel`](/survey-creator/documentation/api-reference/icreatoroptions#maxChoiceContentNestingLevel) property to an integer value. This property defines how many levels of nesting are allowed:

- 0 - Disables nesting (default).
- 1 - Allows first-level choice options to contain survey elements.
- 2 - Allows first- and second-level choice options to contain survey elements, and so on.

In this demo, the `maxChoiceContentNestingLevel` property is set to 2.

## Files

### `public/index.html`

```html
<!-- Uncomment the following lines to enable Ace Editor in the JSON Editor tab -->
<!-- 
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ace.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ext-searchbox.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/theme-clouds_midnight.js"></script>
-->

<div id="surveyCreatorContainer" style="position: absolute; height: 100%; width: 100%"></div>
```

### `src/survey_json.js`

```js
export const surveyJSON = {
  "elements": [
    {
      "type": "checkbox",
      "name": "event_preferences",
      "title": "Which types of events are you interested in attending?",
      "choices": [
        {
          "value": "music",
          "text": "Music events",
          "elements": [
            {
              "type": "checkbox",
              "name": "music_event_type",
              "title": "Which type of music event would you like to attend?",
              "isRequired": true,
              "choices": [
                {
                  "value": "concert",
                  "text": "Concert",
                  "elements": [
                    {
                      "type": "text",
                      "name": "preferred_concert_genre",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "placeholder": "Enter preferred music genre (e.g., Rock, Jazz)"
                    },
                    {
                      "type": "text",
                      "name": "preferred_concert_date",
                      "titleLocation": "hidden",
                      "inputType": "month",
                      "placeholder": "Preferred date"
                    }
                  ]
                },
                {
                  "value": "festival",
                  "text": "Music festival",
                  "elements": [
                    {
                      "type": "text",
                      "name": "preferred_festival_name",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "placeholder": "Enter festival name or type"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "value": "sports",
          "text": "Sports events",
          "elements": [
            {
              "type": "checkbox",
              "name": "sports_event_type",
              "title": "Which sports events are you interested in?",
              "isRequired": true,
              "choices": [
                {
                  "value": "match",
                  "text": "Live match",
                  "elements": [
                    {
                      "type": "dropdown",
                      "name": "preferred_sport",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "choices": [
                        "Football",
                        "Basketball",
                        "Tennis"
                      ],
                      "placeholder": "Select sport"
                    }
                  ]
                },
                {
                  "value": "tournament",
                  "text": "Tournament",
                  "elements": [
                    {
                      "type": "text",
                      "name": "preferred_tournament",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "placeholder": "Enter preferred tournament (e.g., Wimbledon)"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "value": "cultural",
          "text": "Cultural events",
          "elements": [
            {
              "type": "checkbox",
              "name": "cultural_event_type",
              "title": "Which cultural event are you interested in?",
              "isRequired": true,
              "choices": [
                {
                  "value": "museum",
                  "text": "Museum exhibition",
                  "elements": [
                    {
                      "type": "text",
                      "name": "preferred_museum_theme",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "placeholder": "Enter theme or type (e.g., Art, History)"
                    }
                  ]
                },
                {
                  "value": "theater",
                  "text": "Theater performance",
                  "elements": [
                    {
                      "type": "text",
                      "name": "preferred_theater_show",
                      "titleLocation": "hidden",
                      "isRequired": true,
                      "placeholder": "Enter the name of the show"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "checkbox",
      "name": "contact_methods",
      "title": "How may we contact you?",
      "choices": [
        {
          "value": "email",
          "text": "By email",
          "elements": [
            {
              "type": "text",
              "name": "email_address",
              "titleLocation": "hidden",
              "inputType": "email",
              "placeholder": "Enter your email address"
            }
          ]
        },
        {
          "value": "phone_call",
          "text": "By phone call",
          "elements": [
            {
              "type": "text",
              "name": "phone_number_call",
              "titleLocation": "hidden",
              "isRequired": true,
              "inputType": "tel",
              "placeholder": "Enter your phone number"
            },
            {
              "type": "comment",
              "name": "preferred_call_time",
              "titleLocation": "hidden",
              "placeholder": "Enter a convenient time to call"
            }
          ]
        },
        {
          "value": "sms",
          "text": "By SMS",
          "elements": [
            {
              "type": "text",
              "name": "phone_number_sms",
              "titleLocation": "hidden",
              "valueName": "phone_number_call",
              "inputType": "tel",
              "placeholder": "Enter your phone number"
            }
          ]
        },
        {
          "value": "telegram",
          "text": "By Telegram",
          "elements": [
            {
              "type": "text",
              "name": "telegram_username",
              "titleLocation": "hidden",
              "isRequired": true,
              "placeholder": "Enter your Telegram username"
            }
          ]
        }
      ]
    }
  ]
};
```

### `src/SurveyCreatorComponent.jsx`

```js
import React from "react";
import { SurveyCreator, SurveyCreatorComponent } from "survey-creator-react";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { surveyJSON } from "./survey_json";
import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";
import "./index.css";

import SurveyTheme from "survey-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

function SurveyCreatorRenderComponent() {
    const creator = new SurveyCreator({ maxChoiceContentNestingLevel: 2 });
    creator.JSON = surveyJSON;
    return (<SurveyCreatorComponent creator={creator} />);
}

export default SurveyCreatorRenderComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyCreatorRenderComponent from "./SurveyCreatorComponent";

const root = createRoot(document.getElementById("surveyCreatorContainer"));
root.render(<SurveyCreatorRenderComponent />);
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest",
    "survey-creator-core": "latest",
    "survey-creator-react": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/nest-sub-questions-within-choice-options/angular.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/nest-sub-questions-within-choice-options/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/nest-sub-questions-within-choice-options/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/nest-sub-questions-within-choice-options/vanillajs.md)
