Creating a Property Editor

A guide to creating a property editor in Umbraco.

Overview

This guide covers setting up a Property Editor and registering it as a Data Type in Umbraco

The steps covered in part one are:

This tutorial uses TypeScript and Lit. Make sure your package is already set up before continuing.

o set up an extension using TypeScript and Lit, see the Creating your first extension article.

Resources

This tutorial will not go in-depth on how TypeScript and Lit work. To learn about TypeScript and Lit, you can find their documentation below:

The End Result

By the end of this tutorial, you will have a Suggestions Data Type, registered in the backoffice, and assigned to a Document Type. This Data Type can create and suggest values.

circle-info

At the end of the final step, a dropdown displaying the entire suggestions-property-editor-ui.element.ts and umbraco-package.json files is available.

Setting up a plugin

  1. Follow the Vite Package Setup by creating a new project folder called "suggestions" in App_Plugins.

  2. Create a manifest file to define and configure the property editor using either JSON or TypeScript.

Create a manifest file named umbraco-package.json at the root of the suggestions folder, and add the following code:

circle-info

The umbraco-package.json files are cached by the server. When creating new umbraco-package.json files, it might take a few seconds before those are loaded into the server cache.

circle-info

It is important to select the right propertyEditorSchemaAlias as it affects how the Property Editor data is made available when rendering the website.

In this example, Umbraco.Plain.String is selected because a string value is expected. For more options, see the default Property Editor Schema aliases article.

Creating a Web Component

Create the web component for the property editor.

  1. Create a file in the src folder with the name suggestions-property-editor-ui.element.ts

  2. In this new file, add the following code:

  1. In the vite.config.ts file, replace the following:

  • entry to the newly created .ts file.

  • outDir: 'dist' so the output lands in App_Plugins/suggestions/dist/.

The basic parts of the editor are now in place:

  • The package manifest, telling Umbraco what to load

  • The web component for the editor

  1. Run the build. In your terminal, go to the suggestions folder and run:

  1. Reload the backoffice.

Registering the Data Type in Umbraco

  1. Add the newly added property editor "Suggestions" in the Document Type and save it.

Suggestions Property Editor

The property can now be edited using the new Property Editor.

  1. Check out the content where you will see the property editor that looks like this:

The Suggestions property editor displayed in the Umbraco content editor.
The Suggestions property editor in the content editor.

Adding styling and setting up events in the Web Components

Start by creating an input field and some buttons to style and hook up to events.

  1. Update the render method to include some input fields and buttons in the suggestions-property-editor-ui.element.ts file:

circle-info

The Umbraco UI library is already a part of the backoffice, which means it can be used immediately.

  1. Add some styling. Update the import from lit to include css and UmbTextStyles:

  1. Add the CSS:

chevron-rightSee the entire `suggestions-property-editor-ui.element.ts` filehashtag
  1. Run the build. In your terminal, go to the suggestions folder and run:

  1. Reload the backoffice.

It should now look something like this:

The Suggestions property editor with an input field and two buttons.
The property editor after adding the input field and buttons.

Next, set up the event logic.

Setup Event Logic

Setup Input Field

Start with the input field. When typing something in the input field, the property editor's value should change to the input field's current value.

Dispatch a change event using one of two approaches:

  • Using new CustomEvent('change') or

  • Using new UmbChangeEvent() which is recommended as you can leverage the core class

  1. Add the import so the event can be used:

  1. Add the event to the property editor:

Look at the suggestions button next.

Setup Suggestions Button

  • When pressing the suggestion button, the text should update to the suggestion received. Similar to how the value of the property editor changes when writing in the input field.

  • The value should also change when pressing the suggestion button.

  1. Update the import for Lit:

  1. Add suggestions to the property editor:

  1. Update the suggestion button in the render method to call a onSuggestion method when pressing the button:

chevron-rightSee the entire file: suggestions-property-editor-ui.element.tshashtag
  1. Run the build. In your terminal, go to the suggestions folder and run:

  1. Clear your cache and reload the backoffice.

  2. Click on the Give me suggestions button to see the Suggestions Data Type in action.

The Suggestions property editor displaying a randomly selected suggestion value.
The completed Suggestions property editor with event logic in place.

When saving or publishing, the value of the Data Type is automatically synced to the current content object and sent to the server.

To learn more, visit the Property Editors page.

Going further

The Suggestions Data Type is now set up and running. The next part covers adding configurations to the property editor.

Last updated

Was this helpful?