JavaScript/jQuery HtmlEditor - toolbar.items
The toolbar provides predefined items and supports custom items. To add a predefined item to the toolbar, include it in the items array:
Most of the predefined items are buttons. To customize a button, assign its name to the name property and specify the button options in the options object:
To use another UI component instead of a button, specify the widget property and configure the UI component in the options object. In this case, you should also implement all the logic.
The toolbar provides a short syntax for implementing a custom drop-down menu with multiple choices. Refer to the name description for more information.
acceptedValues
Specifies values for a format with multiple choices. Should be used with the name.
Formats with multiple choices are represented by SelectBox UI components whose properties you can specify in the options object.
html
The HtmlEditor component evaluates the html property's value. This evaluation, however, makes the HtmlEditor potentially vulnerable to XSS attacks. To guard against these attacks, encode the HTML markup before you assign it to the html property. Refer to the following help topic for more information: Potentially Vulnerable API - html.
You can use the text property as a safe alternative.
location
Whatever template you use for UI component items (default or a custom) will be located according to the value specified for the location field in the item data source object.
See Also
menuItemTemplate
The following types of the specified value are available.
- Assign a string containing the name of the required template.
- Assign a jQuery object of the template's container.
- Assign a DOM Node of the template's container.
- Assign a function that returns the jQuery object or a DOM Node of the template's container.
- $(function() {
- $("#toolbar").dxToolbar({
- items: [{
- // ...
- menuItemTemplate (data, index) {
- return $(`<div><i class='dx-icon-favorites'></i>${data.options.text}</div>`);
- }
- }],
- });
- });
See Also
name
To customize a predefined item, assign its name to this property and specify the other item properties.
This property also accepts names of formats with multiple choices. In addition to the format name, specify acceptedValues. On the toolbar, such formats are represented by SelectBox UI components whose properties you can specify in the options object.
In the following code, the header
and size
formats are configured as described in the previous paragraph:
- $(function(){
- $("#htmlEditorContainer").dxHtmlEditor({
- toolbar: {
- items: [ // ...
- {
- name: "header",
- acceptedValues: [1, 2, 3, false],
- options: {
- width: 150
- }
- }, {
- name: "size",
- acceptedValues: ["11px", "14px", "16px"]
- }]
- }
- })
- })
Refer to the Formats article for a full list of available formats.
See Also
options
template
The following types of the specified value are available.
- Assign a string containing the name of the required template.
- Assign a jQuery object of the template's container.
- Assign a DOM Node of the template's container.
- Assign a function that returns the jQuery object or a DOM Node of the template's container.
The following example adds a custom item to the component. Note that Angular and Vue use custom templates instead of the template property. In React, specify the render or component properties.
- $(function() {
- $("#htmlEditorContainer").dxHtmlEditor({
- // ...
- toolbar: {
- items: [
- {
- // ...
- template: '<div>Custom Item</div>'
- }
- ]
- }
- });
- });
See Also
widget
Configure the specified UI component in the options object. You can find information on available UI component properties in the UI component's API reference.
In the following example, the CheckBox UI component is added as a custom toolbar item. It has a label and a custom valueChanged event handler. The toolbar item's locateInMenu property is set to "never" to specify that the toolbar item should never be hidden in the overflow menu.