Vue HtmlEditor Methods

This section describes methods that control the HtmlEditor UI component.

See Also

beginUpdate()

Prevents the UI component from refreshing until the endUpdate() method is called.

The beginUpdate() and endUpdate() methods prevent the UI component from excessive updates when you are changing multiple UI component settings at once. After the beginUpdate() method is called, the UI component does not update its UI until the endUpdate() method is called.

See Also

clearHistory()

Clears the history of changes.

See Also

defaultOptions(rule)

Specifies the device-dependent default configuration properties for this component.

Parameters:
rule:

Object

The component's default device properties.

Object structure:
Name Type Description
device

Device

|

Array<Device>

|

Function

Device parameters.
When specifying a function, get information about the current device from the argument. Return true if the properties should be applied to the device.

options

Object

Options to be applied.

defaultOptions is a static method that the UI component class supports. The following code demonstrates how to specify default properties for all instances of the HtmlEditor UI component in an application executed on the desktop.

  • <template>
  • <div>
  • <DxHtmlEditor id="htmlEditor1" />
  • <DxHtmlEditor id="htmlEditor2" />
  • </div>
  • </template>
  • <script>
  • import DxHtmlEditor from "devextreme-vue/html-editor";
  • import HtmlEditor from "devextreme/ui/html_editor";
  •  
  • HtmlEditor.defaultOptions({
  • device: { deviceType: "desktop" },
  • options: {
  • // Here go the HtmlEditor properties
  • }
  • });
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • }
  • }
  • </script>

delete(index, length)

Deletes content from the given range.

Parameters:
index:

Number

A zero-based index at which to begin deleting.

length:

Number

The length of the content to be deleted.
Embedded items have a length of 1.

dispose()

Disposes of all the resources allocated to the HtmlEditor instance.

After calling this method, remove the DOM element associated with the UI component:

JavaScript
  • $("#myHtmlEditor").dxHtmlEditor("dispose");
  • $("#myHtmlEditor").remove();

Use this method only if the UI component was created with jQuery or pure JavaScript. In Angular, Vue, and React, use conditional rendering:

App.vue
  • <template>
  • <DxHtmlEditor ...
  • v-if="condition">
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • }
  • }
  • </script>
See Also

element()

Gets the root UI component element.

Return Value:

HTMLElement | jQuery

An HTML element or a jQuery element when you use jQuery.

See Also

endUpdate()

Refreshes the UI component after a call of the beginUpdate() method.

Main article: beginUpdate()

See Also

focus()

Sets focus on the UI component.

See Also

format(formatName, formatValue)

Applies a format to the selected content. Cannot be used with embedded formats.

Parameters:
formatName:

String

| 'background' | 'bold' | 'color' | 'font' | 'italic' | 'link' | 'size' | 'strike' | 'script' | 'underline' | 'blockquote' | 'header' | 'indent' | 'list' | 'align' | 'code-block'
formatValue: any

A format value.

If no content is selected, the format applies to the character typed next.

App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • makeTextBold() {
  • this.htmlEditor.format("bold", true);
  • },
  • insertGoogleLink() {
  • this.htmlEditor.format("link", {
  • href: "https://www.google.com/",
  • text: "Google",
  • title: "Go to Google"
  • });
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>
See Also

formatLine(index, length, formatName, formatValue)

Applies a single block format to all lines in the given range.

Parameters:
index:

Number

A zero-based index at which to begin formatting.

length:

Number

The length of the content to be formatted.
Embedded items have a length of 1.

formatName:

String

| 'background' | 'bold' | 'color' | 'font' | 'italic' | 'link' | 'size' | 'strike' | 'script' | 'underline' | 'blockquote' | 'header' | 'indent' | 'list' | 'align' | 'code-block'

A format name.

formatValue: any

A format value.

NOTE
The entire line will be formatted even if only a single character from it falls within the given range.
App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • alignFirstLineToRight() {
  • this.htmlEditor.formatLine(0, 1, "align", "right");
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>
See Also

formatLine(index, length, formats)

Applies several block formats to all lines in the given range.

Parameters:
index:

Number

A zero-based index at which to begin formatting.

length:

Number

The length of the content to be formatted.
Embedded items have a length of 1.

formats:

Object

Formats to be applied.
This object should have the following structure:
{ "formatName1": "formatValue1", ... }

NOTE
The entire line will be formatted even if only a single character from it falls within the given range.
App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • applyLineFormats() {
  • this.htmlEditor.formatLine(0, 1, { "align": "right", "list": "ordered" });
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>
See Also

formatText(index, length, formatName, formatValue)

Applies a single text format to all characters in the given range.

Parameters:
index:

Number

A zero-based index at which to begin formatting.

length:

Number

The length of the content to be formatted.
Embedded items have a length of 1.

formatName:

String

| 'background' | 'bold' | 'color' | 'font' | 'italic' | 'link' | 'size' | 'strike' | 'script' | 'underline' | 'blockquote' | 'header' | 'indent' | 'list' | 'align' | 'code-block'

A format name.

formatValue: any

A format value.

App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • makeTextBold() {
  • // Makes the first five characters bold
  • this.htmlEditor.formatText(0, 5, "bold", true);
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>
See Also

formatText(index, length, formats)

Applies several text formats to all characters in the given range.

Parameters:
index:

Number

A zero-based index at which to begin formatting.

length:

Number

The length of the content to be formatted.
Embedded items have a length of 1.

formats:

Object

Formats to be applied.
This object should have the following structure:
{ "formatName1": "formatValue1", ... }

App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • applyLineFormats() {
  • // Makes the first five characters bold and underlined
  • this.htmlEditor.formatText(0, 5, { "bold": "true", "underline": "true" });
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>
See Also

get(componentPath)

Gets a format, module, or Parchment.

Parameters:
componentPath:

String

A path to a format ("formats/[formatName]"), module ("modules/[moduleName]"), or Parchment ("parchment").

Return Value:

Object

A format, module, or Parchment content.

You can perform the following tasks after getting a format, module, or Parchment:

In the following code, the bold format is associated with the <b> tag instead of the default <strong> tag. After the modification, the format is registered.

App.vue
  • <template>
  • <DxHtmlEditor ...
  • :ref="htmlEditorRefName">
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefName = "myHtmlEditor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefName
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefName].instance;
  • }
  • },
  • mounted: function() {
  • this.$nextTick(function() {
  • let Bold = this.htmlEditor.get("formats/bold");
  • Bold.tagName = "b";
  •  
  • this.htmlEditor.register({ "formats/bold": Bold });
  • })
  • }
  • }
  • </script>
See Also

getFormat(index, length)

Gets formats applied to the content in the specified range.

Parameters:
index:

Number

A zero-based index indicating the range's start.

length:

Number

The range's length.
Embedded items have a length of 1.

Return Value:

Object

The applied formats.
This object has the following structure:
{ "formatName1": "formatValue1", ... }

getInstance(element)

Gets the instance of a UI component found using its DOM node.

Parameters:
element:

Element

|

jQuery

The UI component's container.

Return Value:

Object

The UI component's instance.

getInstance is a static method that the UI component class supports. The following code demonstrates how to get the HtmlEditor instance found in an element with the myHtmlEditor ID:

  • // Modular approach
  • import HtmlEditor from "devextreme/ui/html_editor";
  • ...
  • let element = document.getElementById("myHtmlEditor");
  • let instance = HtmlEditor.getInstance(element) as HtmlEditor;
  •  
  • // Non-modular approach
  • let element = document.getElementById("myHtmlEditor");
  • let instance = DevExpress.ui.dxHtmlEditor.getInstance(element);
See Also

getLength()

Gets the entire content's length.

Return Value:

Number

The content's length.

Embedded items have a length of 1.

NOTE
Even if the HtmlEditor is empty, this method returns 1, because the UI component always contains an empty line ("\n").

getModule(moduleName)

Gets the instance of a module.

Parameters:
moduleName:

String

The name of a registered module.

Return Value:

Object

A module's instance.

You can get DevExtreme Quill modules, DevExtreme UI modules, or custom modules.

If you implement the customizeModules function, make sure that it does not disable the modules that you want to get.

getQuillInstance()

Gets the DevExtreme Quill's instance.

Return Value:

Object

The DevExtreme Quill's instance.

getSelection()

Gets the selected content's position and length.

Return Value:

Object

The selected content's range. Has the following structure:

  • index
    A zero-based index at which the selection starts.
  • length
    The selected content's length.
    Embedded items have a length of 1.

insertEmbed(index, type, config)

Inserts an embedded content at the specified position.

Parameters:
index:

Number

A zero-based index at which to insert an embedded content.

type:

String

An embedded format's name.

config: any

An embedded format's value.

App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • insertImageAtTheBeginning() {
  • // Makes the first five characters bold and underlined
  • this.htmlEditor.insertEmbed(0, "extendedImage", {
  • src: "https://js.devexpress.com/Content/images/doc/20_2/PhoneJS/person1.png",
  • alt: "Photo",
  • width: "100px"
  • });
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>

insertText(index, text, formats)

Inserts formatted text at the specified position. Used with all formats except embedded.

Parameters:
index:

Number

A zero-based index at which to insert text.

text:

String

The text to be inserted.

formats:

Object

The formats to be applied.
This object should have the following structure:
{ "formatName1": "formatValue1", ... }

App.vue
  • <template>
  • <DxHtmlEditor :ref="htmlEditorRefKey">
  • <!-- ... -->
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefKey = "my-html-editor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefKey
  • }
  • },
  • methods: {
  • insertTextAtTheBeginning() {
  • // Inserts bold, green text at the beginning of the content
  • this.htmlEditor.insertText(0, "I will be the first", {
  • bold: true,
  • color: "green"
  • });
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefKey].instance;
  • }
  • }
  • }
  • </script>

instance()

Gets the UI component's instance. Use it to access other methods of the UI component.

Return Value:

HtmlEditor

This UI component's instance.

See Also

off(eventName)

Detaches all event handlers from a single event.

Parameters:
eventName:

String

The event's name.

Return Value:

HtmlEditor

The object for which this method is called.

See Also

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

Parameters:
eventName:

String

The event's name.

eventHandler:

Function

The event's handler.

Return Value:

HtmlEditor

The object for which this method is called.

See Also

on(eventName, eventHandler)

Subscribes to an event.

Parameters:
eventName:

String

The event's name.

eventHandler:

Function

The event's handler.

Return Value:

HtmlEditor

The object for which this method is called.

Use this method to subscribe to one of the events listed in the Events section.

See Also

on(events)

Subscribes to events.

Parameters:
events:

Object

Events with their handlers: { "eventName1": handler1, "eventName2": handler2, ...}

Return Value:

HtmlEditor

The object for which this method is called.

Use this method to subscribe to several events with one method call. Available events are listed in the Events section.

See Also

option()

Return Value:

Object

The UI component's properties.

See Also

option(optionName)

Gets the value of a single property.

Parameters:
optionName:

String

The property's name or full path.

Return Value: any

This property's value.

See Also

option(optionName, optionValue)

Updates the value of a single property.

Parameters:
optionName:

String

The property's name or full path.

optionValue: any

This property's new value.

See Also

option(options)

Updates the values of several properties.

Parameters:
options:

Object

Options with their new values.

See Also

redo()

Reapplies the most recent undone change. Repeated calls reapply preceding undone changes.

See Also

register(components)

Registers custom formats and modules.

Parameters:
modules:

Object

Formats and modules to be registered.
This object should have the following structure:
{ "path1": "object1", ... }
where path1 is formats/[formatName] for formats or modules/[moduleName] for modules.

App.vue
  • <template>
  • <DxHtmlEditor ...
  • :ref="htmlEditorRefName">
  • </DxHtmlEditor>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import DxHtmlEditor from 'devextreme-vue/html-editor';
  •  
  • const htmlEditorRefName = "myHtmlEditor";
  •  
  • export default {
  • components: {
  • DxHtmlEditor
  • },
  • data() {
  • return {
  • htmlEditorRefName
  • }
  • },
  • computed: {
  • htmlEditor: function() {
  • return this.$refs[htmlEditorRefName].instance;
  • }
  • },
  • mounted: function() {
  • this.$nextTick(function() {
  • this.htmlEditor.registerModules({ "modules/myModule": moduleObject });
  • })
  • }
  • }
  • </script>
See Also

registerKeyHandler(key, handler)

Registers a handler to be executed when a user presses a specific key.

Parameters:
key:

String

A key.

handler:

Function

A handler. Accepts the keydown event as the argument. It is a dxEvent or a jQuery.Event when you use jQuery.

The key argument accepts one of the following values:

  • "backspace"
  • "tab"
  • "enter"
  • "escape"
  • "pageUp"
  • "pageDown"
  • "end"
  • "home"
  • "leftArrow"
  • "upArrow"
  • "rightArrow"
  • "downArrow"
  • "del"
  • "space"
  • "F"
  • "A"
  • "asterisk"
  • "minus"

A custom handler for a key cancels the default handler for this key.

See Also

removeFormat(index, length)

Removes all formatting and embedded content from the specified range.

Parameters:
index:

Number

A zero-based index at which to begin removing.

length:

Number

The length of the content to be removed.
Embedded items have a length of 1.

repaint()

Repaints the UI component without reloading data. Call it to update the UI component's markup.

See Also

reset()

Resets the value property to the default value.

See Also

resetOption(optionName)

Resets a property to its default value.

Parameters:
optionName:

String

A property's name.

See Also

setSelection(index, length)

Selects and highlights content in the specified range.

Parameters:
index:

Number

A zero-based index at which to begin selecting.

length:

Number

The length of the content to be selected.
Embedded items have a length of 1.

undo()

Reverses the most recent change. Repeated calls reverse preceding changes.

See Also