目录

editor

Represents a rich-text editor component that allows editing of images and text.

The content exported from the editor supports HTML with tags and plain text. Internally, the editor uses the delta format for storage. If you use the setContents API to insert HTML content, some illegal tags may cause parsing errors. Therefore, you are advised to insert content in the delta format when using the editor in the ASCF atomic service.

Related API: EditorContext

Since: 1.0.17

Attributes

Name Type Default Value Mandatory Description
read-only boolean false No Read-only mode for the editor.
placeholder string - No Placeholder text for empty editor content.
enable-formats Array.<string> All formats No

Allowed formats for the editor.

For example, enable-formats=['bold','italic'] means only bold and italic formats take effect. If the enable-formats attribute is not set, all supported formats take effect. For details about the supported formats, see EditorContext.format.

enterkeyhint string enter No

Text displayed on the bottom-right button of the input method keyboard when the editor is tapped to bring up the keyboard. Valid values (support varies across device models and input methods):

- send: The text on the bottom-right button of the keyboard is Send.

- search: The text on the bottom-right button of the keyboard is Search.

- next: The text on the bottom-right button of the keyboard is Next.

- previous: The text on the bottom-right button of the keyboard is Previous.

- go: The text on the bottom-right button of the keyboard is Go.

- done: The text on the bottom-right button of the keyboard is Done.

- enter: The text on the bottom-right button of the keyboard is Enter.

confirm-hold boolean true No Whether to keep the keyboard unfolded when the Enter key is pressed.
bindready eventhandle - No Event triggered when the editor initialization is complete.
bindfocus eventhandle - No Event triggered when the editor is focused, with event.detail = {html,text,delta}.
bindblur eventhandle - No Event triggered when the editor loses focus, with detail = {html,text,delta}.
bindinput eventhandle - No Event triggered when the editor content changes, with detail = {html,text,delta}.
bindstatuschange eventhandle - No Event triggered when styles in the editor are changed via Context methods, returning the current styles applied to the text selection.

Example:

HXML file:

<view class="page-section">
  <editor
    id="editor"
    read-only="{{readOnly}}"
    placeholder="{{placeholder}}"
    enable-formats="{{enableFormats}}"
    enterkeyhint="{{enterkeyhint}}"
    confirm-hold="{{confirmHold}}"
    bindinput="{{onInput}}"
    bindready="{{onReady}}"
    bindblur="{{onBlur}}"
    bindfocus="{{onFocus}}"
    bindstatuschange="{{onStatusChange}}" />
</view>

JavaScript file:

Page({
  data: {
    readOnly: false,
    placeholder: 'Please enter content',
    enableFormats: ['bold'],
    enterkeyhint: 'enter',
    confirmHold: true,
  },
  onReady(e) {
    const info = e.detail;
  },
  onFocus(e) {
    const { html, text, delta } = e.detail;
  },
  onBlur(e) {
    const { html, text, delta } = e.detail;
  },
  onInput(e) {
    const { html, text, delta } = e.detail;
  },
  onStatusChange(e) {
    const info = e.detail;
  }
});