diff --git a/workspaces/orchestrator/.changeset/scope-async-validation-to-step.md b/workspaces/orchestrator/.changeset/scope-async-validation-to-step.md new file mode 100644 index 0000000000..e83b4863b7 --- /dev/null +++ b/workspaces/orchestrator/.changeset/scope-async-validation-to-step.md @@ -0,0 +1,5 @@ +--- +'@red-hat-developer-hub/backstage-plugin-orchestrator-form-react': patch +--- + +Scope async validate:url calls to the active step in multi-step forms. diff --git a/workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorFormWrapper.tsx b/workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorFormWrapper.tsx index 78a170682b..313d8b58ec 100644 --- a/workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorFormWrapper.tsx +++ b/workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorFormWrapper.tsx @@ -91,11 +91,22 @@ const FormComponent = (decoratorProps: FormDecoratorProps) => { let _extraErrors: ErrorSchema | undefined = undefined; let _validationError: Error | undefined = undefined; const activeKey = getActiveKey(); + const shouldScopeExtraErrors = + Boolean(activeKey) && Boolean(uiSchema?.[activeKey as string]); + const extraErrorsFormData = (_formData ?? formData) as JsonObject; + const extraErrorsUiSchema = shouldScopeExtraErrors + ? ({ + [activeKey as string]: uiSchema?.[activeKey as string], + } as OrchestratorFormContextProps['uiSchema']) + : uiSchema; if (decoratorProps.getExtraErrors) { try { handleValidateStarted(); - _extraErrors = await decoratorProps.getExtraErrors(formData, uiSchema); + _extraErrors = await decoratorProps.getExtraErrors( + extraErrorsFormData, + extraErrorsUiSchema, + ); if (activeKey) { setExtraErrors(