For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding Configuration to a Property Editor

Adding configuration options to the editor.

Overview

This is step two in the guide to building a Property Editor. This step builds on part one and covers adding configuration options to the editor.

This article covers the following:

Configuration

An important part of building good Property Editors is making them flexible so they can be reused in many contexts. The Rich Text Editor, for example, lets you choose which buttons and stylesheets to use per instance.

The same editor can be reused with different configurations.

Adding settings object to umbraco-package.json

To add a Data Type configuration field to the Suggestion Property Editor:

  1. Open the umbraco-package.json file.

  2. Add the settings object inside the meta object.

  3. Add some properties:

umbraco-package.json
    ...
    "meta": {
        ...
        "settings": {
            "properties": [
                {
                    "alias": "disabled",
                    "label": "Disabled",
                    "description": "Disables the suggestion button",
                    "propertyEditorUiAlias": "Umb.PropertyEditorUi.Toggle"
                },
                {
                    "alias": "placeholder",
                    "label": "Placeholder text",
                    "description": "A nice placeholder description to help out our editor!",
                    "propertyEditorUiAlias": "Umb.PropertyEditorUi.TextBox"
                },
                {
                    "alias": "maxChars",
                    "label": "Max characters allowed",
                    "description": "The maximum number of allowed characters in a suggestion",
                    "propertyEditorUiAlias": "Umb.PropertyEditorUi.Integer"
                }
            ]
        }
        ...
    }

The code above adds three configuration fields. Each entry in the properties collection represents a Configuration field.

  • Disabled uses the Toggle Property Editor UI. This enables to switch the suggestion button on or off and provides the user with a toggle button.

  • Placeholder text uses the TextBox Property Editor UI, allowing the user to write a text.

  • Max characters allowed uses the Integer Property Editor UI, enabling the user to enter a numeric value.

The Property Editor UI needs to be declared as it declares what User Interface should be used for this field.

You can use any Property Editor UI to define Configuration fields. The alias of a given Property Editor UI can be found in Data Type configurations using that Property Editor.

  1. Add default values for the new configuration fields:

See the entire file: umbraco-package.json
  1. Save the files and reload the backoffice. You can now see the Configurations in the Data Type:

Data Type configuration.

Using the configuration

The next step is to gain access to our new configuration options. For this, open the suggestions-property-editor-ui.element.ts file.

  1. Create some state variables that can store our configurations:

  1. Let's create a config property. Add a new import and add the following property:

  1. Look up the alias of the config and then grab the value by said alias:

Let's use the placeholder and maxChars for the input field and the disabled option for the suggestion button.

  1. Add a new import ifDefined :

  1. Update the render method:

See the entire file: suggestions-property-editor-ui.element.ts
  1. Run the command npm run build in the suggestions folder.

  2. Run the project.

  3. Go to the Content section of the Backoffice to see the new changes in the property editor:

Suggestions Property Editor with disabled suggestions option

Going further

The Data Type now has configuration options wired up to the Property Editor. The next part covers integrating context with the Property Editor.

Last updated

Was this helpful?