Skip to main content

setValue()

Description

Applies a new value to RichText

Usage

setValue: (value: string, encoder?: any): void;

Parameters

  • value - (required) a value to be inserted into the RichText
  • encoder - (optional) a custom parser used to decode the value from a custom format. The following formats are available: html (default), text, and markdown

You can get the required encoder in the following way:

const fromTextEncoder = richtext.text.fromText;             // text encoder
const fromHTMLEncoder = richtext.html.fromHTML; // html encoder
const fromMarkdownEncoder = richtext.markdown.fromMarkdown; // markdown encoder

Example

const editor = new richtext.Richtext("#root", {
// configuration properties
});

const editor_value = "Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos."

const fromTextEncoder = richtext.text.fromText;
editor.setValue(editor_value, fromTextEncoder);

Change log: The method was updated in v2.0. The mode parameter was removed. The encoder parameter was added

Related sample: RichText. Working with different formats (Markdown, HTML, text)