Vue HtmlEditor Methods
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
defaultOptions(rule)
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)
dispose()
Use conditional rendering instead of this method:
- <template>
- <DxHtmlEditor ...
- v-if="condition">
- </DxHtmlEditor>
- </template>
- <script>
- import DxHtmlEditor from 'devextreme-vue/html-editor';
- export default {
- components: {
- DxHtmlEditor
- }
- }
- </script>
format(formatName, formatValue)
Applies a format to the selected content. Cannot be used with embedded formats.
A format name.
If no content is selected, the format applies to the character typed next.
- <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.
The length of the content to be formatted.
Embedded items have a length of 1.
A format name.
- <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.
The length of the content to be formatted.
Embedded items have a length of 1.
- <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.
The length of the content to be formatted.
Embedded items have a length of 1.
A format name.
- <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.
The length of the content to be formatted.
Embedded items have a length of 1.
- <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.
You can perform the following tasks after getting a format, module, or Parchment:
Modify the format
You can change the markup tag associated with the format and allowed format values, as shown in the code example after this list.Extend the format or module
You can extend HtmlEditor's formats and modules, and also the DevExtreme Quill's formats and modules. See the Extend Built-In Formats and Modules topic for the code example.Create a custom format based on the Parchment
Refer to the Parchment documentation for more information.
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.
- <template>
- <DxHtmlEditor ...
- :ref="htmlEditorRefName">
- </DxHtmlEditor>
- </template>
- <script>
- 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)
getInstance(element)
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()
Embedded items have a length of 1.
getModule(moduleName)
The name of a registered module.
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.
getSelection()
The selected content's range. It 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)
- <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/21_2/PhoneJS/person1.png",
- alt: "Photo",
- width: "100px"
- });
- }
- },
- computed: {
- htmlEditor: function() {
- return this.$refs[htmlEditorRefKey].instance;
- }
- }
- }
- </script>
insertText(index, text, formatName, formatValue)
insertText(index, text, formats)
Inserts formatted text at the specified position. Used with all formats except embedded.
- <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>
on(eventName, eventHandler)
Use this method to subscribe to one of the events listed in the Events section.
See Also
on(events)
Use this method to subscribe to several events with one method call. Available events are listed in the Events section.
See Also
register(components)
- <template>
- <DxHtmlEditor ...
- :ref="htmlEditorRefName">
- </DxHtmlEditor>
- </template>
- <script>
- 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)
A handler. Accepts the keydown event as the argument. It is a EventObject 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)
setSelection(index, length)
If you have technical questions, please create a support ticket in the DevExpress Support Center.