Skip to content

Commit

Permalink
Merge pull request #96 from episerver/feature/AFORM-3946-hide-rich-text
Browse files Browse the repository at this point in the history
Don't show confirmation message when the form and the message is empty
  • Loading branch information
epi-qang2 authored Jan 26, 2024
2 parents 2d80aec + 54508d9 commit aa6ba5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/@episerver/forms-react/src/components/FormBody.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useEffect, useRef } from "react";
import { useForms } from "../context/store";
import { StepHelper, FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull, isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache, FormConstants, ProblemDetail, StepDependCondition, buildConfirmMessage } from "@episerver/forms-sdk";
import { StepHelper, FormContainer, FormSubmitter, IdentityInfo, isInArray, isNull,
isNullOrEmpty, FormSubmitModel, FormSubmitResult, SubmitButton, FormCache,
FormConstants, ProblemDetail, StepDependCondition, getConfirmationData } from "@episerver/forms-sdk";
import { RenderElementInStep } from "./RenderElementInStep";
import { DispatchFunctions } from "../context/dispatchFunctions";
import { FormStepNavigation } from "./FormStepNavigation";
Expand Down Expand Up @@ -61,15 +63,20 @@ export const FormBody = (props: FormBodyProps) => {
submissionWarning.current = !isNullOrEmpty(error);
message.current = error;
}

const handleConfirm = () => {
const confirmationMessage = form.properties.confirmationMessage;
const form = formContext?.formContainer ?? {} as FormContainer;
const confirmationMessage = form.properties.confirmationMessage ?? "";
let confimStatus = true;

if (!isNullOrEmpty(confirmationMessage) && form.properties.showSummarizedData) {
if (form.properties.showSummarizedData) {
const data = formContext?.formSubmissions ?? []
const confirmationMessageWithData = buildConfirmMessage(confirmationMessage, data, form)
confimStatus = confirm(confirmationMessageWithData);
}
const messageData = getConfirmationData(data, form)
const showConfirmationMessage = !(isNullOrEmpty(confirmationMessage) && isNullOrEmpty(messageData))
if (showConfirmationMessage) {
confimStatus = confirm(confirmationMessage + "\n\n" + messageData);
}
}

return confimStatus
}
Expand All @@ -91,7 +98,6 @@ export const FormBody = (props: FormBodyProps) => {

let isLastStep = currentStepIndex === form.steps.length - 1;


//filter submissions by active elements and current step
let formSubmissions = (formContext?.formSubmissions ?? [])
.filter(fs => !isInArray(fs.elementKey, formContext?.dependencyInactiveElements ?? []) && stepHelper.isInCurrentStep(fs.elementKey, currentStepIndex));
Expand Down
11 changes: 6 additions & 5 deletions src/@episerver/forms-sdk/src/helpers/buildConfirmationMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { isNullOrEmpty } from "./utils";
export const FieldsToIgnore = [
"FormStepBlock",
"SubmitButtonElementBlock",
"PredefinedHiddenElementBlock"
"PredefinedHiddenElementBlock",
"ParagraphTextElementBlock"
]

export function getValueAsString(element: FormSubmission) {
Expand All @@ -26,15 +27,15 @@ export function getValueAsString(element: FormSubmission) {
return `${value}`
}

export function buildConfirmMessage(confirmationMessage: string, data: FormSubmission[], form: FormContainer, fieldsToIgnore?: string[]): string {
const newLine = "\n"
let message = confirmationMessage + newLine;
export function getConfirmationData(data: FormSubmission[], form: FormContainer, fieldsToIgnore?: string[]): string {
let message = "";
let _fieldsToIgnore = fieldsToIgnore ?? FieldsToIgnore;

data.forEach(element => {
let formElement = form.formElements.find(fe => fe.key === element.elementKey)
let value = getValueAsString(element)
if (formElement && !isNullOrEmpty(value) && _fieldsToIgnore.indexOf(formElement.contentType) === -1) {
message += `${formElement.displayName}: ${value}${newLine}`;
message += `${formElement.displayName}: ${value}${"\n"}`;
}
});

Expand Down

0 comments on commit aa6ba5e

Please sign in to comment.