-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into bugfix/AFORM-3801-Form-multi-steps-workin…
- Loading branch information
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/@episerver/forms-react/src/components/elements/ParagraphTextElementBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { FormCache, FormContainer, FormStorage, ParagraphText, Url } 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 { useForms } from "../../context/store"; | ||
|
||
export interface ParagraphTextElementBlockProps { | ||
element: ParagraphText | ||
} | ||
|
||
export const ParagraphTextElementBlock = (props: ParagraphTextElementBlockProps) => { | ||
const { element } = props; | ||
const { elementContext, handleChange, handleBlur } = useElement(element); | ||
const { isVisible, validationResults, value, validatorClasses } = elementContext; | ||
const formContext = useForms(); | ||
const form = formContext?.formContainer as FormContainer | ||
const formKey = form.key; | ||
|
||
const formStorage = new FormStorage(form); | ||
const data = formStorage.loadFormDataFromStorage(); | ||
|
||
const doReplaceText = element.properties.disablePlaceholdersReplacement ?? true | ||
|
||
function extractTextsWithFormat(inputString: string) { | ||
const regex = /::(.*?)::/g; | ||
const matches = inputString.match(regex); | ||
if (matches) { | ||
return matches.map(match => match.slice(2, -2)); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
let text = element.properties.paragraphText | ||
const placeHolders = extractTextsWithFormat(element.properties.paragraphText) | ||
|
||
if (doReplaceText) { | ||
data.forEach(element => { | ||
const key = element.elementKey | ||
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) | ||
} | ||
}); | ||
} | ||
|
||
console.log(text) | ||
|
||
return useMemo(() => ( | ||
<ElementWrapper className={`FormParagraphText Form__Element--NonData ${validatorClasses}`} validationResults={validationResults} isVisible={isVisible}> | ||
<ElementCaption element={element} /> | ||
<> | ||
<div id={formKey} > | ||
<div dangerouslySetInnerHTML={{ | ||
__html: text | ||
}}/> | ||
</div> | ||
<div id={formKey + "__OriginalText"} className="Form__Original__ParagraphText"> | ||
|
||
</div> | ||
</> | ||
</ElementWrapper > | ||
), [isVisible, validationResults, value]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters