---
title: Add a Modal Editor to the Property Grid
product: Survey Creator
description: Learn how to enhance your survey elements by adding a modal editor to the Property Grid of your fully integrated form builder. This demo demonstrates how to implement a custom property editor that enables survey authors to manage access rules for a selected question within a pop-up dialog. View a free demo example for JavaScript to learn more.
framework: jQuery
source: https://surveyjs.io/survey-creator/examples/add-modal-property-editor-to-property-grid/jquery
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Add a Modal Editor to the Property Grid (jQuery)

Survey elements come with a variety of built-in properties that cover most use cases. If you want to extend the available functionality, you can [add custom properties](/survey-creator/examples/add-properties-to-property-grid/) to survey elements and [implement custom property editors](/survey-creator/examples/customize-property-editors/). This example demonstrates a custom editor that allows survey authors to configure properties in a pop-up dialog. To open the dialog, click the Set Access Rules button. The dialog features a dynamic table where you can add or remove access rules for the selected question.

Follow the steps below to configure a modal property editor for a custom property:

1. Add a custom property to a question type.            
Call the `addProperty(className, propMeta)` method on the `Serializer` object. `className` is the name of a base or derived class (see the [`getType()`](https://surveyjs.io/form-library/documentation/api-reference/question#getType) method description); `propMeta` is a JSON object with [property settings](https://surveyjs.io/form-library/documentation/customize-question-types/add-custom-properties-to-a-form#survey-element-property-settings).

1. Add an editor for the custom property.           
Register the property editor in the `PropertyGridEditorCollection` and specify a standard JSON object that the custom type should produce. For instance, in this demo, the custom editor is a Dynamic Matrix. 

1. Define a survey JSON schema for the modal dialog.            
The modal dialog is built upon a regular SurveyJS survey. To specify the dialog's content, configure a survey JSON schema and use it to instantiate a [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model) object.

1. Add a button that opens the dialog to the editor title.          
Implement an [`onPropertyEditorUpdateTitleActions`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onPropertyEditorUpdateTitleActions) event handler. Within it, check that the event is raised for a required property and add an [`IAction`](https://surveyjs.io/form-library/documentation/api-reference/iaction) configuration object to the `options.titleActions` array. This configuration object should include the [`action`](https://surveyjs.io/form-library/documentation/api-reference/iaction#action) function.

1. Open the dialog on a button click.         
Call the global `showDialog` method within the `action` function to open the custom dialog when users click the button. Use the method's parameters to specify a `SurveyModel` instance that represents the dialog's content and define handling functions for the Apply and Cancel buttons. When a user clicks Apply, retrieve values from the pop-up survey using its `data` property and assign them to the current question. Refer to the code listing for details.

## 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/index.css`

```css
.sv-property-editor .sd-root-modern {
    min-width: 640px;
}
```

### `src/index.js`

```js
import { SurveyCreator } from "survey-creator-js";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { SurveyModel, Serializer, settings } from "survey-core";
import { PropertyGridEditorCollection, getLocaleStrings } from "survey-creator-core";
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

// Step 1: Add a custom property to a question type
Serializer.addProperty("question", {
  name: "accessRules",
  type: "accessrules",
  category: "accessRules",
  showValueInLink: false
});

// Step 2: Add an editor for the custom property
PropertyGridEditorCollection.register({
  fit: (prop) => prop.type === "accessrules",
  getJSON: () => {
    return {
      "type": "matrixdynamic",
      "rowCount": 0,
      "allowRemoveRows": false,
      "columns": [
        {
          "name": "userRole",
          "title": "User Role",
          "cellType": "dropdown",
          "readOnly": true,
          "isRequired": true,
          "choices": [
            { "value": "admin", "text": "Admin" },
            { "value": "editor", "text": "Editor" },
            { "value": "viewer", "text": "Viewer" },
            { "value": "guest", "text": "Guest" }
          ]
        },
        {
          "name": "permissions",
          "title": "Permissions",
          "cellType": "dropdown",
          "readOnly": true,
          "choices": [
            { "value": "view", "text": "View" },
            { "value": "edit", "text": "Edit" }
          ],
          "showNoneItem": true,
          "noneText": "No access"
        }
      ]
    }
  }
});

const translation = getLocaleStrings("en");
translation.pe.tabs.accessRules = "Access Rules";
translation.pehelp.accessRules = "Specify user roles that can interact with the selected form element and define their permissions.";

const creator = new SurveyCreator();
// Step 3: Define a survey JSON schema for the modal dialog
const popupJson = {
  "elements": [
    {
      "type": "matrixdynamic",
      "name": "accessRules",
      "titleLocation": "hidden",
      "columns": [
        {
          "name": "userRole",
          "title": "User Role",
          "isRequired": true,
          "cellType": "dropdown",
          "isUnique": true,
          "choices": [
            { "value": "admin", "text": "Admin" },
            { "value": "editor", "text": "Editor" },
            { "value": "viewer", "text": "Viewer" },
            { "value": "guest", "text": "Guest" }
          ]
        },
        {
          "name": "permissions",
          "title": "Permissions",
          "cellType": "dropdown",
          "defaultValue": "Edit",
          "choices": [
            { "value": "view", "text": "View" },
            { "value": "edit", "text": "Edit" }
          ],
          "showNoneItem": true,
          "noneText": "No access"
        }
      ],
      "rowCount": 0,
      "maxRowCount": 4,
      "addRowText": "Add Access Rule"
    }
  ],
  "showNavigationButtons": false
};

const popupSurvey = new SurveyModel(popupJson);

// Step 4: Add a button that opens the dialog to the editor title
creator.onPropertyEditorUpdateTitleActions.add((_, options) => {
  if (options.property.name === "accessRules") {
    popupSurvey.setValue("accessRules", options.element.accessRules);
    options.titleActions.push({
      id: "setAccessRules",
      title: "Set Access Rules",
      // Step 5: Open the dialog on a button click
      action: () => {
        settings.showDialog({
          componentName: "survey",
          data: { model: popupSurvey },
          onApply: () => {
            const validAccessRules = popupSurvey.validate();
            if (validAccessRules) {
              // Get values from the pop-up survey using its `data` property
              // and update the current question (`options.element`)
              options.element.setPropertyValue("accessRules", popupSurvey.data["accessRules"]);
              return true;
            }
            return false;
          },
          onCancel: () => {
            console.log("Cancel");
          },
          cssClass: "sv-property-editor",
          title: "Configure Access Rules for " + options.element.title,
          displayMode: "popup"
        }, creator.rootElement)
      }
    });
  }
});

creator.JSON = {
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "text",
          "name": "userName",
          "title": "User Name",
          "accessRules": [
            { "userRole": "admin", "permissions": "edit" },
            { "userRole": "viewer", "permissions": "view" },
            { "userRole": "guest", "permissions": "none" }
          ]
        },
        {
          "type": "text",
          "name": "dob",
          "title": "Date of Birth",
          "maskType": "datetime",
          "maskSettings": {
            "pattern": "m-dd-yyyy"
          }
        }
      ]
    }
  ]
}

creator.showSidebar = true;
creator.selectedElement = creator.survey.getQuestionByName("userName");
creator.expandPropertyGridCategory("accessRules");
creator.render("surveyCreatorContainer");
```

### `package.json`

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

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/add-modal-property-editor-to-property-grid/angular.md)
- [React](https://surveyjs.io/survey-creator/examples/add-modal-property-editor-to-property-grid/reactjs.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/add-modal-property-editor-to-property-grid/vue3js.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/add-modal-property-editor-to-property-grid/vanillajs.md)
