Sub topic 13
Building a custom property editor
This chapter assumes you can already expose a component with the lightning__FlowScreen target and declare property elements in meta.xml. It also assumes you can dispatch a basic CustomEvent.
Why build one
By default, Flow Builder shows one generic input for each property you declare. That works for simple values. It falls short when you need a picklist of allowed choices, fields that depend on each other, or a live preview. A custom property editor (CPE) is a second Lightning web component that replaces that default form in the builder.
The editor runs only while an admin configures the flow. It never runs when a user runs the flow.
Connect the editor in meta.xml
Add the configurationEditor attribute to the targetConfig. Its value is the editor's tag name in c-kebab-case. Keep the property elements. They define the data the editor reads and writes.
<targetConfig targets="lightning__FlowScreen" configurationEditor="c-quantity-picker-editor">
<property name="label" type="String" label="Field label" default="Quantity"/>
<property name="quantity" type="Integer" label="Quantity"/>
</targetConfig>The editor bundle also needs its own meta.xml with isExposed set to true. It needs no targets.
How the builder and editor talk
Flow Builder passes the current configuration into the editor through @api properties. The editor sends changes back by dispatching an event.
The @api properties the builder sets are:
| Property | Contents |
|---|---|
| `inputVariables` | Array of `{ name, value, valueDataType }` for each component property |
| `genericTypeMappings` | The chosen sObject type for each `propertyType` |
| `builderContext` | Other flow resources, such as variables and record types |
Write the editor
This editor shows one text field for label. It reads the current value from inputVariables and reports edits to the builder.
<template>
<lightning-input
label="Field label"
value={label}
onchange={handleChange}>
</lightning-input>
</template>import { LightningElement, api } from 'lwc';
export default class QuantityPickerEditor extends LightningElement {
@api inputVariables = [];
get label() {
const variable = this.inputVariables.find((v) => v.name === 'label');
return variable ? variable.value : '';
}
handleChange(event) {
this.dispatchEvent(
new CustomEvent('configuration_editor_input_value_changed', {
bubbles: true,
cancelable: false,
composed: true,
detail: {
name: 'label',
newValue: event.target.value,
newValueDataType: 'String'
}
})
);
}
@api validate() {
const errors = [];
if (!this.label || !this.label.trim()) {
errors.push({ key: 'EMPTY_LABEL', errorString: 'Enter a field label.' });
}
return errors;
}
}The event detail must contain name (the property name from meta.xml), newValue, and newValueDataType. The event needs bubbles and composed set to true, or the builder never receives it.
The editor's validate() differs from the component's validate(). It returns an array of { key, errorString } objects, and an empty array means the configuration is valid. The builder calls it when the admin saves the flow or closes the screen element.
Common errors
- Nothing saves. The event name is misspelled, or
composedis missing. The builder ignores events it cannot receive. - Fields reset to blank. The editor keeps its own copy of the state instead of reading
inputVariables. After each event the builder sends the stored values back, so read from there. - Values from flow resources break. An admin can map a property to a flow variable instead of typing a literal. In that case
valueDataTypeisreference, andvalueis a string such asmyVar, not a literal. CheckvalueDataTypebefore you showvaluein a plain input. - The editor does not load. The tag name in
configurationEditordoes not match the bundle name. For example, thequantityPickerEditorbundle becomesc-quantity-picker-editor.
Exercise
The admin types a new label in your custom property editor, but Flow Builder keeps the old value. The editor dispatches new CustomEvent('configuration_editor_input_value_changed', { detail: { name: 'label', newValue: 'Qty', newValueDataType: 'String' } }). What is the likely cause, and how do you fix it?
Show answer
The event has no bubbles: true and composed: true, so it never leaves the editor's shadow DOM to reach Flow Builder. Add both options to the CustomEvent constructor.