Skip to main content

Notifications

Rich Text to Plain Text conversion inside Power Apps

Guido Preite Profile Picture Guido Preite 54,059 Super User

Sometimes we need to get only the text from an HTML document, like the Rich Text format available for the text type inside Dataverse/Model-driven app.

If you need to perform this action client-side, a simple JavaScript function can be used:

function parseHTML(html) {
	let doc = new DOMParser().parseFromString(html, 'text/html');
	return doc.body.textContent || "";
}

function test_richtext_OnChange(executionContext) {
	var formContext = executionContext.getFormContext();
	let richTextValue = formContext.getAttribute("test_richtext").getValue();
	let cleanValue = parseHTML(richTextValue);
	formContext.getAttribute("test_plaintext").setValue(cleanValue);
}

It uses the DOMParser interface, here a screenshot on how the result looks like inside a model-driven app:



Hope it helps!

This was originally posted here.

Comments

*This post is locked for comments