I have a document with multiple variables (plain text like {ID} or {Requester}) and I want to replace variables programmatically. Below code works fine if there is one placeholder ( {ID} ). For 2 or 2 more placeholders,browser freezes. Any solution?
if (documentEditorContainer && documentEditorContainer.current) {
const placeholders: { [key: string]: string } = ({
ID: '12345',
Requester: 'John Doe'
});
const replacePlaceholders = () => {
if (documentEditorContainer.current && placeholders) {
for (const [key, value] of Object.entries(placeholders)) {
documentEditorContainer.current.documentEditor.search.findAll(`{${key}}`);
if (documentEditorContainer.current?.documentEditor.search.searchResults.length > 0) {
documentEditorContainer.current?.documentEditor.search.searchResults.replaceAll(value);
}
documentEditorContainer.current?.documentEditor.search.searchResults.clear();
}
}
};
const loadDocument = async () => {
documentEditorContainer.current.documentEditor.open(JSON.parse(requestTemplate.DocumentJSON));
replacePlaceholders();
};
loadDocument();
}
});