Skip to content

Commit

Permalink
fix(FormRenderer-Wizard): Fix an issue where validation can be skippe…
Browse files Browse the repository at this point in the history
…d in certain scenarios. Close #991 (#995)
  • Loading branch information
jessieweiyi authored Oct 30, 2023
1 parent b5cc8e2 commit c0b2f53
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const Wizard: FC<WizardProps> = ({
const formOptions = useFormApi();
const { isSubmitting } = useFormRendererContext();
const [activeStepIndex, setActiveStepIndex] = useState(props.activeStepIndex || 0);
const [maxStepIndex, setMaxStepIndex] = useState(0);
const [isLoadingNextStep, setIsLoadingNextStep] = useState(props.isLoadingNextStep || isSubmitting);
const [errorText, setErrorText] = useState<string>();

Expand Down Expand Up @@ -132,6 +133,7 @@ const Wizard: FC<WizardProps> = ({
const response = await handleNavigating(event);
if (response.continued) {
setActiveStepIndex(requestedStepIndex);
setMaxStepIndex((prev) => (requestedStepIndex > prev ? requestedStepIndex : prev));
} else {
setErrorText(response.errorText);
}
Expand All @@ -144,7 +146,7 @@ const Wizard: FC<WizardProps> = ({
setErrorText(undefined);
const requestedStepIndex = event.detail.requestedStepIndex;

if (activeStepIndex < event.detail.requestedStepIndex) {
if (activeStepIndex < event.detail.requestedStepIndex || activeStepIndex < maxStepIndex) {
const state = formOptions.getState();
setShowError(true);
if (!(state.invalid || state.validating || state.submitting)) {
Expand All @@ -154,7 +156,7 @@ const Wizard: FC<WizardProps> = ({
processNavigate(requestedStepIndex, event);
}
},
[activeStepIndex, formOptions, processNavigate]
[activeStepIndex, maxStepIndex, formOptions, processNavigate]
);

return (
Expand Down

0 comments on commit c0b2f53

Please sign in to comment.