Defining a default value for a custom property editor triggers unsaved changes on new documents

I have built a simple custom property editor. In the settings for my property editor I have defined a field for a default value. I am fetching this default value inside my custom element like this:

I have my property value:

  @property({ type: String })
  public value = "";

I also have a setter for config:

  public set config(config: UmbPropertyEditorConfigCollection | undefined) {
    const defaultValue = config.getValueByAlias<string>("defaultValue") ?? "";

    if (!this.value && defaultValue) {
      this.value = defaultValue;
      this.dispatchEvent(new UmbPropertyValueChangeEvent());
    }
  }

As you can see, I check if our current value is empty and we have a non-falsy defaultValue. In this case I want to use the defaultValue as my real value.

This works! But I am inadvertently introducing a quirk here - any “new” document using this property editor will act is if the user has edited the content. So just opening up a new document and then trying to navigate away from it gives this screen:

I understand why this happens, but I don’t know how to properly define a default value. Is this possible within the scope of Lit/backoffice extension limited to “frontend” code? Or do I have to handle this purely in backend instead?

“default value” or as they are now called: “Property Value Preset” was released with Umbraco 15.3.0 this week:

There’s some documentation here that hopefully helps:

2 Likes

Fantastic timing, thank you again Sebastiaan :smiley:

1 Like

I can now also confirm that this worked great to implement.

I’ll add that the docs there doesn’t show what you need to import, but it’s as simple as:

import type { UmbPropertyValuePreset } from "@umbraco-cms/backoffice/property";
import type { UmbPropertyEditorConfig } from "@umbraco-cms/backoffice/property-editor";
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.