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:
Open the
umbraco-package.jsonfile.Add the
settingsobject inside themetaobject.Add some
properties:
...
"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.
Disableduses the Toggle Property Editor UI. This enables to switch the suggestion button on or off and provides the user with a toggle button.Placeholder textuses the TextBox Property Editor UI, allowing the user to write a text.Max characters alloweduses the Integer Property Editor UI, enabling the user to enter a numeric value.
Add default values for the new configuration fields:
Save the files and reload the backoffice. You can now see the Configurations in the Data Type:

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.
Create some state variables that can store our configurations:
Let's create a config property. Add a new import and add the following property:
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.
Add a new import
ifDefined:
Update the render method:
Run the command
npm run buildin thesuggestionsfolder.Run the project.
Go to the Content section of the Backoffice to see the new changes in the property editor:

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?