Skip to content

Commit

Permalink
Fix go previous step incorrectly
Browse files Browse the repository at this point in the history
Fixes: AFORM-3912
  • Loading branch information
hungoptimizely committed Jan 19, 2024
1 parent b78db0d commit daf220f
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from "react";
import { useForms } from "../context/store";
import { FormCache, FormConstants, FormContainer, StepDependCondition, SubmitButtonType, isNull, isNullOrEmpty } from "@episerver/forms-sdk";
import { FormCache, FormConstants, FormContainer, FormStorage, StepDependCondition, SubmitButtonType, isNull, isNullOrEmpty } from "@episerver/forms-sdk";
import { DispatchFunctions } from "../context/dispatchFunctions";

interface FormStepNavigationProps {
Expand All @@ -21,6 +21,7 @@ export const FormStepNavigation = (props: FormStepNavigationProps) => {
const dispatchFuncs = new DispatchFunctions();
const stepLocalizations = useRef<Record<string, string>>(form.steps?.filter(s => !isNull(s.formStep.localizations))[0]?.formStep.localizations).current;
const isNextStep = useRef<boolean>(false);
const formStorage = new FormStorage(form);

const submittable = true
const stepCount = form.steps.length;
Expand All @@ -35,6 +36,8 @@ export const FormStepNavigation = (props: FormStepNavigationProps) => {

const handlePrevStep = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault()
// when go back, we don't need to validate, just save the state
formStorage.saveFormDataToStorage(formContext?.formSubmissions ?? []); // save form state before changing step
goToStep(depend.findPreviousStep(currentStepIndex) ?? 0)
}

Expand Down

0 comments on commit daf220f

Please sign in to comment.