From daf220f5cf0ffb356e585e774347f8249e1dd7b2 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Fri, 19 Jan 2024 13:22:05 +0700 Subject: [PATCH] Fix go previous step incorrectly Fixes: AFORM-3912 --- .../forms-react/src/components/FormStepNavigation.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/@episerver/forms-react/src/components/FormStepNavigation.tsx b/src/@episerver/forms-react/src/components/FormStepNavigation.tsx index 214706b..0a72b77 100644 --- a/src/@episerver/forms-react/src/components/FormStepNavigation.tsx +++ b/src/@episerver/forms-react/src/components/FormStepNavigation.tsx @@ -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 { @@ -21,6 +21,7 @@ export const FormStepNavigation = (props: FormStepNavigationProps) => { const dispatchFuncs = new DispatchFunctions(); const stepLocalizations = useRef>(form.steps?.filter(s => !isNull(s.formStep.localizations))[0]?.formStep.localizations).current; const isNextStep = useRef(false); + const formStorage = new FormStorage(form); const submittable = true const stepCount = form.steps.length; @@ -35,6 +36,8 @@ export const FormStepNavigation = (props: FormStepNavigationProps) => { const handlePrevStep = (event: React.MouseEvent) => { 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) }