Skip to content

Commit

Permalink
Merge pull request #63 from episerver/bugfix/AFORM-3838-Not-handle-fo…
Browse files Browse the repository at this point in the history
…r-Store-form-submissions-option

Fix error when disable Store form submission
  • Loading branch information
hungoptimizely authored Jan 2, 2024
2 parents 58c1c9f + 7f6d91a commit 90902f1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
27 changes: 14 additions & 13 deletions src/@episerver/forms-react/src/components/FormBody.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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("<br/>") }
}) ?? [];

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("<br/>") }
}) ?? [];

dispatchFunctions.updateAllValidation(formValidationResults);

//set focus on the 1st invalid element of current step
dispatchFunctions.updateFocusOn(stepHelper.getFirstInvalidElement(formValidationResults, currentStepIndex));
}
break;
}

Expand Down
3 changes: 1 addition & 2 deletions src/@episerver/forms-sdk/src/form-step/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./stepBuilder";
export * from "./stepDependCondition";
export * from "./stepHelper";
export * from "./stepDependCondition";
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/@episerver/forms-sdk/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./urlHelper";
export * from "./elementHelper";
export * from "./utils";
export * from "./fileHelper";
export * from "./initFormState";
export * from "./initFormState";
export * from "./stepHelper";
2 changes: 1 addition & 1 deletion src/@episerver/forms-sdk/src/helpers/initFormState.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { equals, isNull, isNullOrEmpty } from "../helpers";
import { equals, isNull, isNullOrEmpty } from "./utils";
import { FormContainer, FormValidationResult } from "../models";

/**
Expand Down

0 comments on commit 90902f1

Please sign in to comment.