Hybrid authoring allows users to either edit fields manually or populate them automatically from an external source.
To achieve this:
- Define an
external field to select the source data. - Define standard fields (e.g.,
type: "text") for manual editing. - Use
resolveData to map properties from the external data to the standard fields. - Use the
readOnly property in the resolveData return object to lock the standard fields when external data is present, preventing accidental overrides.
const config = {
components: {
Example: {
fields: {
data: {
type: "external",
// ... fetchList and getItemSummary
},
title: {
type: "text",
},
},
resolveData: async ({ props }, { changed }) => {
// If no external data is selected, allow manual editing of the title
if (!props.data) return { props, readOnly: { title: false } };
// If data changed, sync the title from the external source and lock the field
if (!changed.data) return { props };
return {
props: {
title: props.data.title,
},
readOnly: { title: true },
};
},
render: ({ title }) => <b>{title}</b>,
},
},
};