From 4314c5dd98b5f2631e47de1377a72a0daa85e133 Mon Sep 17 00:00:00 2001 From: "EP\\qang2" Date: Wed, 27 Dec 2023 17:33:18 +0700 Subject: [PATCH] Add htmlDecodeEntities to helper functions. --- .../components/elements/ParagraphTextElementBlock.tsx | 2 +- .../components/elements/ResetButtonElementBlock.tsx | 5 ++++- src/@episerver/forms-sdk/src/helpers/utils.ts | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx b/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx index d0296ee..881535f 100644 --- a/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx +++ b/src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx @@ -11,7 +11,7 @@ export interface ParagraphTextElementBlockProps { export const ParagraphTextElementBlock = (props: ParagraphTextElementBlockProps) => { const { element } = props; - const { elementContext, handleChange, handleBlur } = useElement(element); + const { elementContext } = useElement(element); const { isVisible, validationResults, value, validatorClasses } = elementContext; const formContext = useForms(); const form = formContext?.formContainer as FormContainer diff --git a/src/@episerver/forms-react/src/components/elements/ResetButtonElementBlock.tsx b/src/@episerver/forms-react/src/components/elements/ResetButtonElementBlock.tsx index baf391f..8471bf6 100644 --- a/src/@episerver/forms-react/src/components/elements/ResetButtonElementBlock.tsx +++ b/src/@episerver/forms-react/src/components/elements/ResetButtonElementBlock.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from "react"; import { FormContainer, ResetButton } from "@episerver/forms-sdk"; import { useElement } from "../../hooks/useElement"; import { useForms } from "../../context/store"; +import { htmlDecodeEntities } from "@episerver/forms-sdk/src/helpers/dependencyHelper"; interface ResetButtonElementBlockProps { element: ResetButton @@ -15,8 +16,10 @@ export const ResetButtonElementBlock = (props: ResetButtonElementBlockProps) => const formContext = useForms(); const form = formContext?.formContainer ?? {} as FormContainer; + + const handleResetButton = () => { - if (confirm(form.properties.resetConfirmationMessage)) { + if (confirm(htmlDecodeEntities(form.properties.resetConfirmationMessage))) { handleReset() } } diff --git a/src/@episerver/forms-sdk/src/helpers/utils.ts b/src/@episerver/forms-sdk/src/helpers/utils.ts index 693e798..23ebd42 100644 --- a/src/@episerver/forms-sdk/src/helpers/utils.ts +++ b/src/@episerver/forms-sdk/src/helpers/utils.ts @@ -71,4 +71,15 @@ export function isInArray (value: string, arrayString: string[], ignoreCase: boo arrayString = arrayString.map(s => s.toLowerCase()); } return arrayString.indexOf(value) > -1; +} + +/** + * Decodes HTML entities in a given encoded string and returns the decoded string.. + * @param {string} encodedString - The string containing HTML-encoded entities to be decoded. + * @returns {string} - The decoded string with HTML entities replaced by their corresponding characters. + */ +export function htmlDecodeEntities(encodedString: string) : string{ + var textArea = document.createElement("textarea"); + textArea.innerHTML = encodedString; + return textArea.value; } \ No newline at end of file