Skip to content

Commit f030878

Browse files
authored
fix: Validation errors incorrectly shown on wrong step when navigating back (#1958)
* fix: Validation errors incorrectly shown on wrong step When using widgets with validate:url, the getExtraErrors callback validates all fields across all steps. The previous logic falls back to the full error object when the current step had no errors. This fix: - Sets extraErrors to undefined when current step has no errors - Updates step navigation to only check current step's errors * fix: update prettier formatting
1 parent a698bf0 commit f030878

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-react': patch
3+
---
4+
5+
Fix validation errors incorrectly shown on wrong step when navigating back.
6+
7+
When using widgets with `validate:url`, the `getExtraErrors` callback validates all fields across all steps and returns a nested error object. The previous logic had full error object when the current step had no errors, causing validation errors from other steps to appear on the wrong step.
8+
9+
This fix:
10+
11+
- Sets `extraErrors` to `undefined` when current step has no errors
12+
- Updates step navigation to only check current step's errors before proceeding

workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorFormWrapper.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,38 @@ const FormComponent = (decoratorProps: FormDecoratorProps) => {
9090
setExtraErrors(undefined);
9191
let _extraErrors: ErrorSchema<JsonObject> | undefined = undefined;
9292
let _validationError: Error | undefined = undefined;
93+
const activeKey = getActiveKey();
94+
9395
if (decoratorProps.getExtraErrors) {
9496
try {
9597
handleValidateStarted();
9698
_extraErrors = await decoratorProps.getExtraErrors(formData, uiSchema);
97-
const activeKey = getActiveKey();
98-
setExtraErrors(
99-
activeKey && _extraErrors?.[activeKey]
100-
? (_extraErrors[activeKey] as ErrorSchema<JsonObject>)
101-
: _extraErrors,
102-
);
99+
100+
if (activeKey) {
101+
setExtraErrors(
102+
_extraErrors?.[activeKey]
103+
? (_extraErrors[activeKey] as ErrorSchema<JsonObject>)
104+
: undefined,
105+
);
106+
} else {
107+
setExtraErrors(_extraErrors);
108+
}
103109
} catch (err) {
104110
_validationError = err as Error;
105111
} finally {
106112
handleValidateEnded();
107113
}
108114
}
109115
setValidationError(_validationError);
116+
117+
const currentStepErrors = activeKey
118+
? _extraErrors?.[activeKey]
119+
: _extraErrors;
120+
const hasCurrentStepErrors =
121+
currentStepErrors && Object.keys(currentStepErrors).length > 0;
122+
110123
if (
111-
(!_extraErrors || Object.keys(_extraErrors).length === 0) &&
124+
!hasCurrentStepErrors &&
112125
!_validationError &&
113126
activeStep < (numStepsInMultiStepSchema ?? 1)
114127
) {

0 commit comments

Comments
 (0)