Skip to content

Commit

Permalink
Add htmlDecodeEntities to helper functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
epi-qang2 committed Dec 27, 2023
1 parent fa0bcad commit 4314c5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/@episerver/forms-sdk/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4314c5d

Please sign in to comment.