diff --git a/.changeset/scaffolder-form-context.md b/.changeset/scaffolder-form-context.md new file mode 100644 index 0000000000..08295c6b85 --- /dev/null +++ b/.changeset/scaffolder-form-context.md @@ -0,0 +1,21 @@ +--- +'@backstage/plugin-scaffolder': minor +--- + +Get data of other fields in Form from a custom field in template Scaffolder. +following: + +```tsx +const CustomFieldExtensionComponent(props: FieldExtensionComponentProps) => { + const { formContext } = props; + ... +}; + +const CustomFieldExtension = scaffolderPlugin.provide( + createScaffolderFieldExtension({ + name: ..., + component: CustomFieldExtensionComponent, + validation: ... + }) +); +``` diff --git a/docs/features/software-templates/writing-custom-field-extensions.md b/docs/features/software-templates/writing-custom-field-extensions.md index 8618e04781..5fe3349285 100644 --- a/docs/features/software-templates/writing-custom-field-extensions.md +++ b/docs/features/software-templates/writing-custom-field-extensions.md @@ -161,3 +161,20 @@ spec: description: My custom name for the component ui:field: MyCustomExtension ``` + +## Get data of other fields in Form from a Custom Field Extension + +```tsx +const CustomFieldExtensionComponent(props: FieldExtensionComponentProps) => { + const { formContext } = props; + ... +}; + +const CustomFieldExtension = scaffolderPlugin.provide( + createScaffolderFieldExtension({ + name: ..., + component: CustomFieldExtensionComponent, + validation: ... + }) +); +``` diff --git a/plugins/scaffolder/src/components/MultistepJsonForm/MultistepJsonForm.tsx b/plugins/scaffolder/src/components/MultistepJsonForm/MultistepJsonForm.tsx index a868c50d7a..8db409ed38 100644 --- a/plugins/scaffolder/src/components/MultistepJsonForm/MultistepJsonForm.tsx +++ b/plugins/scaffolder/src/components/MultistepJsonForm/MultistepJsonForm.tsx @@ -198,6 +198,7 @@ export const MultistepJsonForm = (props: Props) => { widgets={widgets} noHtml5Validate formData={formData} + formContext={formData} onChange={onChange} onSubmit={e => { if (e.errors.length === 0) handleNext();