Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/api/methods/insert-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
sidebar_label: insertValue()
title: insertValue Method
description: You can learn about the insertValue method in the documentation of the DHTMLX JavaScript RichText library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX RichText.
---

# insertValue()

### Description

@short: Inserts a value at the current cursor position or replaces the selected text
Comment thread
serhiipylypchuk1991 marked this conversation as resolved.
Outdated

### Usage

~~~jsx {}
insertValue: (value: string, encoder?: any): void;
~~~

### Parameters

- `value` - (required) a value to be inserted into the RichText at the current cursor position. If a selection is active, the selection is replaced with the new value
- `encoder` - (optional) a parser used to decode the inserted value from a custom format. The following formats are available: `html` (default), `text`, and `markdown`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"custom format" is somewhat misleading. only 3 formats are supported, which is said later. so just drop "from a custom format"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрал «from a custom format» — оставил только перечень поддерживаемых форматов ниже.


You can get the required encoder in the following way:

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

### Example

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

// inserts an HTML link with custom attributes at the cursor position
editor.insertValue("<a href=\"https://example.com\" title=\"Example\">link</a>");
~~~

The inserted content is added as a single history entry and can be reverted with one **Undo** step.

**Change log:** The method was added in v2.1
1 change: 1 addition & 0 deletions docs/api/overview/main_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ new richtext.RichText("#root", {
| ----------------------------------------------|-------------------------------------------|
| [](api/methods/get-value.md) | @getshort(api/methods/get-value.md) |
| [](api/methods/set-value.md) | @getshort(api/methods/set-value.md) |
| [](api/methods/insert-value.md) | @getshort(api/methods/insert-value.md) |
| [](api/methods/set-config.md) | @getshort(api/methods/set-config.md) |
| [](api/methods/set-locale.md) | @getshort(api/methods/set-locale.md) |
| [](api/methods/destructor.md) | @getshort(api/methods/destructor.md) |
Expand Down
1 change: 1 addition & 0 deletions docs/api/overview/methods_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ Use this reference to quickly navigate to detailed descriptions of each method,
| [](api/methods/destructor.md) | @getshort(api/methods/destructor.md) |
| [](api/methods/get-value.md) | @getshort(api/methods/get-value.md) |
| [](api/methods/set-value.md) | @getshort(api/methods/set-value.md) |
| [](api/methods/insert-value.md) | @getshort(api/methods/insert-value.md) |
| [](api/methods/set-config.md) | @getshort(api/methods/set-config.md) |
| [](api/methods/set-locale.md) | @getshort(api/methods/set-locale.md) |
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
"api/methods/destructor",
"api/methods/get-value",
"api/methods/set-value",
"api/methods/insert-value",
"api/methods/set-config",
"api/methods/set-locale"
]
Expand Down