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?
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";