DEV Community

Kevin Jump
Kevin Jump

Posted on

2

Early Adopter's guide to Umbraco v14 - Property Editors - UI

Once we have defined the schema and UI manifests for our property editor we can create an element for the user.

UI Element

The UI element is what the editor sees when they are using your property editor.

@customElement('styled-textbox')
export class StyledTextboxUiElement extends LitElement 
     implements UmbPropertyEditorUiElement {

      @property()
      value: undefined | String = '' ;

      @state() 
      _styleValue? : string;

      @property({ attribute: false })
      public set config(config: UmbPropertyEditorConfigCollection | undefined) {
          this._styleValue = config?.getValueByAlias('styleValue') ?? '';
      }

      onChange(e: Event) {
        const newValue = (e.target as HTMLInputElement).value;
        if (newValue === this.value) return;
        this.value = newValue;
        console.log(this.value);
        this.dispatchEvent(new CustomEvent('property-value-change'));
      }

      render() {
        return html`
            <uui-input
              .value=${this.value ?? ''}
              .style=${this._styleValue}
              type="text"
              @input=${this.onChange}></uui-input>
        `;
      }

      static styles = css`
        uui-input {
          width: 100%;
        }`;
}
Enter fullscreen mode Exit fullscreen mode

The editor has a couple of 'special' behaviors, that make it work as a propertyEditor ui.

The value.

All property editors have a value property - this is the property that Umbraco will fill with the data from the item (content, media etc).

@property()
value: undefined | String = '' ;
Enter fullscreen mode Exit fullscreen mode

The value is also what you set when the editor changes the value.

Config

The config property is called to load up your settings from the propertyEditor's configuration (things that are set in the settings section).

here you load the values by their alias, and can set local values so you can access them in your code.

@property({ attribute: false })
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
    this._styleValue = config?.getValueByAlias('styleValue') ?? '';
}
Enter fullscreen mode Exit fullscreen mode

dispatching the "'property-value-change" event.

Finally you're editor should dispatch the 'property-value-change event
when ever you change your value property.

this tells the parent elements in Umbraco that you have change the value, and it updates the model for the item. So when the user clicks save (or publish) the model contains your changes and is saved back into umbraco.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
yusufaffandi profile image
yusufaffandi • Edited

Hi Kevin, great articles.

I'm very new to .NET and Umbraco and want to ask about how to save array of object value to database in custom property editor? I'm tried using UmbPropertyValueChangeEvent but it's not worked. It's been a week to find examples or solution about this.

I appreciate your help. Thanks!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay