Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when disable Store form submission #63

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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