From 3355df0a0c9b4499a909f88987dd6fb4a4958f71 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Mon, 8 Jan 2024 08:35:38 +0700 Subject: [PATCH 1/4] Fix cannot submit when form having multi conditions Fixes: AFORM-3862 --- src/@episerver/forms-react/src/hooks/useElement.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/@episerver/forms-react/src/hooks/useElement.ts b/src/@episerver/forms-react/src/hooks/useElement.ts index 659ba25..9a2302b 100644 --- a/src/@episerver/forms-react/src/hooks/useElement.ts +++ b/src/@episerver/forms-react/src/hooks/useElement.ts @@ -97,13 +97,20 @@ export const useElement = (element: FormElementBase) => { //update form state let inactives = formContext?.dependencyInactiveElements ?? []; + let needUpdate = false; if(isVisible.current){ - inactives = inactives.filter(ek => !equals(ek, element.key)); + if(inactives.includes(element.key)){ + inactives = inactives.filter(ek => !equals(ek, element.key)); + needUpdate = true; + } } else { - !isInArray(element.key, inactives) && inactives.push(element.key); + if(!isInArray(element.key, inactives)){ + inactives.push(element.key); + needUpdate = true; + } } - dispatchFuncs.updateDependencies(inactives); + needUpdate && dispatchFuncs.updateDependencies(inactives); },[formContext?.formSubmissions]); //focus on element if validate fail before submitting From 10b3fdf4396b3124356cd58b3d317f89710a3b24 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Mon, 8 Jan 2024 09:55:21 +0700 Subject: [PATCH 2/4] Show success message when submit progressive Fixes: AFORM-3860 --- src/@episerver/forms-react/src/components/FormBody.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/@episerver/forms-react/src/components/FormBody.tsx b/src/@episerver/forms-react/src/components/FormBody.tsx index 96b7423..24611b6 100644 --- a/src/@episerver/forms-react/src/components/FormBody.tsx +++ b/src/@episerver/forms-react/src/components/FormBody.tsx @@ -154,10 +154,13 @@ export const FormBody = (props: FormBodyProps) => { dispatchFunctions.updateSubmissionKey(response.submissionKey); localFormCache.set(submissionStorageKey, response.submissionKey); + if (isFormFinalized.current || isProgressiveSubmit.current) { + message.current = response.messages.map(m => m.message).join("
"); + } + if (isFormFinalized.current) { formCache.remove(FormConstants.FormCurrentStep + form.key); localFormCache.remove(submissionStorageKey); - message.current = response.messages.map(m => m.message).join("
"); //redirect after submit let redirectToPage = submitButton?.properties?.redirectToPage if(!isNullOrEmpty(redirectToPage)){ From 3df9e60494d77b209cc2865cf0f550b153513b79 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Mon, 8 Jan 2024 10:13:22 +0700 Subject: [PATCH 3/4] Fix error when submit button has a condition Fixes: AFORM-3861 --- src/@episerver/forms-react/src/hooks/useElement.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/@episerver/forms-react/src/hooks/useElement.ts b/src/@episerver/forms-react/src/hooks/useElement.ts index 659ba25..bea0234 100644 --- a/src/@episerver/forms-react/src/hooks/useElement.ts +++ b/src/@episerver/forms-react/src/hooks/useElement.ts @@ -117,7 +117,7 @@ export const useElement = (element: FormElementBase) => { //disable submit button when form submitting useEffect(()=>{ - if(equals(element.contentType, "SubmitButtonElementBlock")){ + if(equals(element.contentType, "SubmitButtonElementBlock") && elementRef.current){ elementRef.current.disabled = formContext?.isSubmitting ?? false; } },[formContext?.isSubmitting]) From 7a2a101a32e843fe1413b70abd65270f8f7de1d5 Mon Sep 17 00:00:00 2001 From: Manh Hung Nguyen Date: Mon, 8 Jan 2024 16:03:15 +0700 Subject: [PATCH 4/4] Fix richtext show 'undefined' when element no data Fixes: AFORM-3868 --- samples/ManagementSite/Alloy.ManagementSite.csproj | 2 +- .../src/components/elements/FileUploadElementBlock.tsx | 4 ++-- .../src/components/elements/ParagraphTextElementBlock.tsx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/ManagementSite/Alloy.ManagementSite.csproj b/samples/ManagementSite/Alloy.ManagementSite.csproj index 54f6238..a3410e2 100644 --- a/samples/ManagementSite/Alloy.ManagementSite.csproj +++ b/samples/ManagementSite/Alloy.ManagementSite.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/@episerver/forms-react/src/components/elements/FileUploadElementBlock.tsx b/src/@episerver/forms-react/src/components/elements/FileUploadElementBlock.tsx index be0ab75..3010e9a 100644 --- a/src/@episerver/forms-react/src/components/elements/FileUploadElementBlock.tsx +++ b/src/@episerver/forms-react/src/components/elements/FileUploadElementBlock.tsx @@ -1,4 +1,4 @@ -import { FileUpload, FormContainer, FormStorage, isNullOrEmpty } from "@episerver/forms-sdk" +import { FileUpload, FormContainer, FormStorage } from "@episerver/forms-sdk" import React, { useMemo } from "react"; import ElementWrapper from "./shared/ElementWrapper"; import { useElement } from "../../hooks/useElement"; @@ -42,7 +42,7 @@ export const FileUploadElementBlock = (props: FileUploadElementBlockProps) => { />
- (Previous posted file(s): {prevFilenames} ) + {prevFilenames && <>(Previous posted file(s): {prevFilenames} )}
diff --git a/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx b/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx index ebbdcdf..25651b7 100644 --- a/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx +++ b/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx @@ -1,8 +1,8 @@ -import { FormCache, FormContainer, FormStorage, ParagraphText, Url } from "@episerver/forms-sdk" +import { FormContainer, FormStorage, ParagraphText } from "@episerver/forms-sdk" import React, { useMemo } from "react"; import ElementWrapper from "./shared/ElementWrapper"; import { useElement } from "../../hooks/useElement"; -import { ElementCaption, ValidationMessage } from "./shared"; +import { ElementCaption } from "./shared"; import { useForms } from "../../context/store"; export interface ParagraphTextElementBlockProps { @@ -38,7 +38,7 @@ export const ParagraphTextElementBlock = (props: ParagraphTextElementBlockProps) if (doReplaceText) { data.forEach(element => { const key = element.elementKey - const value = element.value as string + const value = element.value as string ?? ""; const friendlyName = form.formElements.find(fe => fe.key === key)?.displayName if (friendlyName && placeHolders.indexOf(friendlyName) !== -1) { text = text.replace("::" + friendlyName + "::", value)