diff --git a/src/@episerver/forms-react/src/components/FormBody.tsx b/src/@episerver/forms-react/src/components/FormBody.tsx index 77feb39..d980759 100644 --- a/src/@episerver/forms-react/src/components/FormBody.tsx +++ b/src/@episerver/forms-react/src/components/FormBody.tsx @@ -1,10 +1,9 @@ import React, { useEffect, useRef } from "react"; import { useForms } from "../context/store"; -import { FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull, isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache, FormConstants, ProblemDetail, StepDependCondition } from "@episerver/forms-sdk"; +import { StepHelper, FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull, isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache, FormConstants, ProblemDetail, StepDependCondition } from "@episerver/forms-sdk"; import { RenderElementInStep } from "./RenderElementInStep"; import { DispatchFunctions } from "../context/dispatchFunctions"; import { FormStepNavigation } from "./FormStepNavigation"; -import { StepHelper } from "@episerver/forms-sdk/dist/form-step/stepHelper"; interface FormBodyProps { identityInfo?: IdentityInfo; @@ -127,17 +126,19 @@ export const FormBody = (props: FormBodyProps) => { formCache.remove(FormConstants.FormAccessToken); break; case 400: - //validate fail - validateFail.current = false; - let formValidationResults = formContext?.formValidationResults?.map(fr => isNull(e.errors[fr.elementKey]) ? fr : { - ...fr, - result: { valid: false, message: e.errors[fr.elementKey].join("
") } - }) ?? []; - - dispatchFunctions.updateAllValidation(formValidationResults); - - //set focus on the 1st invalid element of current step - dispatchFunctions.updateFocusOn(stepHelper.getFirstInvalidElement(formValidationResults, currentStepIndex)); + if(e.errors){ + //validate fail + validateFail.current = false; + let formValidationResults = formContext?.formValidationResults?.map(fr => isNull(e.errors[fr.elementKey]) ? fr : { + ...fr, + result: { valid: false, message: e.errors[fr.elementKey].join("
") } + }) ?? []; + + dispatchFunctions.updateAllValidation(formValidationResults); + + //set focus on the 1st invalid element of current step + dispatchFunctions.updateFocusOn(stepHelper.getFirstInvalidElement(formValidationResults, currentStepIndex)); + } break; } diff --git a/src/@episerver/forms-sdk/src/form-step/index.ts b/src/@episerver/forms-sdk/src/form-step/index.ts index e3a16e7..2b66595 100644 --- a/src/@episerver/forms-sdk/src/form-step/index.ts +++ b/src/@episerver/forms-sdk/src/form-step/index.ts @@ -1,3 +1,2 @@ export * from "./stepBuilder"; -export * from "./stepDependCondition"; -export * from "./stepHelper"; \ No newline at end of file +export * from "./stepDependCondition"; \ No newline at end of file diff --git a/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts b/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts index b456293..280cf99 100644 --- a/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts +++ b/src/@episerver/forms-sdk/src/form-step/stepDependCondition.ts @@ -2,7 +2,7 @@ import { ConditionFunctions } from "../form-depend-conditions/ConditionFunctions import { FormStorage } from "../form-storage"; import { equals, isInArray, isNullOrEmpty } from "../helpers"; import { FormContainer, FormStep } from "../models"; -import { StepHelper } from "./stepHelper"; +import { StepHelper } from "../helpers/stepHelper"; /** * Class to help check step is satisfy depend condition diff --git a/src/@episerver/forms-sdk/src/helpers/index.ts b/src/@episerver/forms-sdk/src/helpers/index.ts index 1aa7a55..19c01fc 100644 --- a/src/@episerver/forms-sdk/src/helpers/index.ts +++ b/src/@episerver/forms-sdk/src/helpers/index.ts @@ -3,4 +3,5 @@ export * from "./urlHelper"; export * from "./elementHelper"; export * from "./utils"; export * from "./fileHelper"; -export * from "./initFormState"; \ No newline at end of file +export * from "./initFormState"; +export * from "./stepHelper"; \ No newline at end of file diff --git a/src/@episerver/forms-sdk/src/helpers/initFormState.ts b/src/@episerver/forms-sdk/src/helpers/initFormState.ts index 0f86ecf..eb728b0 100644 --- a/src/@episerver/forms-sdk/src/helpers/initFormState.ts +++ b/src/@episerver/forms-sdk/src/helpers/initFormState.ts @@ -1,5 +1,5 @@ import { FormCache } from "../form-cache"; -import { StepHelper } from "../form-step"; +import { StepHelper } from "./stepHelper"; import { FormStorage } from "../form-storage"; import { FormConstants, FormContainer, FormState, FormSubmission, FormValidationResult, StepDependencies } from "../models"; import { getDefaultValue } from "./elementHelper"; diff --git a/src/@episerver/forms-sdk/src/form-step/stepHelper.ts b/src/@episerver/forms-sdk/src/helpers/stepHelper.ts similarity index 98% rename from src/@episerver/forms-sdk/src/form-step/stepHelper.ts rename to src/@episerver/forms-sdk/src/helpers/stepHelper.ts index 3bb1193..67eb834 100644 --- a/src/@episerver/forms-sdk/src/form-step/stepHelper.ts +++ b/src/@episerver/forms-sdk/src/helpers/stepHelper.ts @@ -1,4 +1,4 @@ -import { equals, isNull, isNullOrEmpty } from "../helpers"; +import { equals, isNull, isNullOrEmpty } from "./utils"; import { FormContainer, FormValidationResult } from "../models"; /**