Html Area
<et2-htmlarea> | Et2HtmlArea
Rich text editor widget built on TinyMCE’s web component.
Et2HtmlArea provides both rich text and plain text editing modes, integrates with EGroupware
upload and language preferences, and exposes a small extension surface for editor-specific integrations such
as custom toolbar buttons.
Examples
Basic
A rich text editor. With nothing set it uses the toolbar from the user’s
rte_toolbar preference, which is what most templates want - the user has already said how much
toolbar they like.
<et2-htmlarea label="Notes"></et2-htmlarea>
Toolbar mode
mode overrides that preference with a fixed preset, for a field where the available formatting
should not vary between users:
mode="simple"- the simple presetmode="extended"- the extended presetmode="advanced"- the advanced presetmode="ascii"- a plain textarea, no editor at allmodeempty (the default) - the user’srte_toolbarpreference
If you need a fixed toolbar regardless of the user preference, set mode explicitly.
<et2-htmlarea label="Simple preset" mode="simple"></et2-htmlarea>
To hide the toolbar entirely, use noToolbar.
<et2-htmlarea label="No toolbar" noToolbar></et2-htmlarea>
Plain Text Mode
mode="ascii" renders a textarea instead of TinyMCE when editable, while preserving the same
value, disabled, placeholder, focus, input, and change contracts as rich text mode.
<et2-htmlarea label="Plain text" mode="ascii" placeholder="Enter plain text"></et2-htmlarea>
Readonly Rendering
Readonly htmlareas render their value directly instead of initializing TinyMCE or a textarea. Rich text
values are rendered as HTML; mode="ascii" values are rendered as literal text.
The lightweight et2-htmlarea_ro element is registered for readonly widget substitution,
including nextmatch detached row updates.
File Selection And Uploads
Dropped and pasted images upload through EGroupware’s HTMLArea upload endpoint by default. Set
image-upload to a VFS target widget id, content path, absolute path, or external URL when the
upload destination needs to be explicit.
TinyMCE’s image, media, and file dialogs use the EGroupware VFS picker unless a custom
filePickerCallback property is assigned.
Submit-time Formatting
Set apply-default-font when saved markup needs to carry the user’s preferred font and size
inline, such as mail compose content that may be read by clients that strip editor CSS. The normalization
happens during getValue(true), so it affects submitted rich-text content rather than the live
editor appearance.
Custom Toolbar Buttons
Integrations can extend the TinyMCE toolbar without reaching through the legacy
editor property. Add the toolbar item name with addToolbarItem(), then register
the TinyMCE UI in registerEditorSetupHook(). TinyMCE documents the available toolbar button
APIs in its
custom toolbar buttons documentation.
The hook must be registered before TinyMCE finishes initializing. If an integration wraps or creates the
htmlarea, call these methods as soon as the Et2HtmlArea instance is available.
import type {Et2HtmlArea} from "./Et2HtmlArea";
function addInsertGreetingButton(htmlarea : Et2HtmlArea)
{
htmlarea.addToolbarItem("insertGreeting");
htmlarea.registerEditorSetupHook("example-greeting-button", editor =>
{
editor.ui.registry.addButton("insertGreeting", {
text: "Greeting",
tooltip: "Insert greeting",
onAction: () =>
{
editor.insertContent("<p>Hello</p>");
}
});
});
}
Use a stable, integration-specific key for registerEditorSetupHook() so it can be replaced or
removed later with unregisterEditorSetupHook(). The toolbar item name passed to
addToolbarItem() must match the TinyMCE control name registered with
editor.ui.registry.
Legacy Compatibility
The component keeps a small compatibility bridge while older integrations move off direct TinyMCE access:
tinymceresolves with the TinyMCE editor arrayeditorexposes the active TinyMCE editor-
file_picker_callback,images_upload_handler,valid_children, andtoolbar_modemap to their modern camelCase properties
New integrations should prefer the component properties plus addToolbarItem() and
registerEditorSetupHook() for editor UI extensions.
Slots
| Name | Description |
|---|---|
label
|
The editor’s label. Alternatively, use the label attribute. |
help-text
|
Text that describes how to use the editor. Alternatively, use the statustext attribute.
|
field-controls
|
Controls shown over the top-right corner of the field (et2-ai’s button, in ascii mode - in TinyMCE mode it goes into the toolbar instead). |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
applyDefaultFont
apply-default-font
|
Force default font and size as style attribute into the markup. Also ensures all non-block elements are wrapped in p. Use this when users really want the font & size (email). |
boolean
|
false
|
|
filePickerCallback
|
Callback function to get called when file picker is clicked. |
TinyMceFilePickerCallback | null
|
null
|
|
height
|
Height. Applied to the widget host by Et2Widget; the editor fills the host and does not
mirror this into TinyMCE’s own sizing config.
|
string
|
""
|
|
mode
|
One of {ascii|simple|extended|advanced}.
simple, extended, and advanced force built-in toolbar presets
and do not use the rte_toolbar preference. Leave mode empty to use the user
preference-driven toolbar.
|
HtmlAreaMode | string
|
""
|
|
noMenubar
no-menubar
|
Disables the menubar at the top of the editor. |
boolean
|
false
|
|
noStatusbar
no-statusbar
|
Disables the status bar on the bottom of the editor. The status bar is off by default. Set
no-statusbar="false" in modern usage, or statusbar="true" in legacy
templates, to enable it.
|
boolean
|
true
|
|
noToolbar
no-toolbar
|
Disables the toolbar at the top of the editor. |
boolean
|
false
|
|
placeholder
|
Placeholder text shown when the editor is empty. |
string
|
""
|
|
toolbarMode
toolbar-mode
|
Controls how toolbar items are shown when space is limited. |
"floating" | "sliding" | "scrolling" | "wrap"
|
"sliding"
|
|
validChildren
valid-children
|
Enables to control what child tag is allowed or not allowed of the present tag. For instance: +body[style], makes style tag allowed inside body. |
string
|
"+body[style]"
|
|
value
|
The value of the widget. |
string
|
""
|
|
width
|
Width. Applied to the widget host by Et2Widget; the editor fills the host and does not
mirror this into TinyMCE’s own sizing config.
|
string
|
""
|
|
editor
|
Compatibility bridge: legacy callers expect direct access to the editor instance.
New integrations should add explicit component APIs instead. |
TinyMceEditor | null
|
- | |
file_picker_callback
|
Compatibility bridge: TinyMCE callback surface retained for migration.
Replace with explicit component APIs where possible. |
TinyMceFilePickerCallback | null
|
- | |
images_upload_handler
|
Compatibility bridge: legacy TinyMCE callback surface retained for migration.
Replace with explicit component APIs where possible. |
TinyMceUploadHandler | null
|
- | |
imagesUploadHandler
|
Callback function for handling image upload.
for a NEW integration: set the `imageUpload` attribute to a literal menuaction URL instead (see _getImageUploadUrl()’s own docblock) - a JS property set after this widget’s first render has no effect (ticket #125961: |
TinyMceUploadHandler | null
|
null
|
|
tinymce
|
Compatibility bridge: legacy integrations still expect a tinymce promise resolving like
tinymce.init().
New integrations should use the component instance directly. |
Promise
|
new Promise(resolve => { this._resolveTinymce = resolve; })
|
|
toolbar_mode
|
Compatibility bridge for legacy snake_case property naming.
Use toolbarMode. |
string
|
- | |
valid_children
|
Compatibility bridge for legacy snake_case property naming.
Use validChildren. |
string
|
- |
Learn more about attributes and properties.
Inherited properties (25)
Et2Widget
| Name | Description |
|---|---|
accesskey |
Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character. |
actions |
Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts. |
align |
Used by Et2Box to determine alignment. Allowed values are left, right |
class |
CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component. |
data |
Set the dataset from a CSV |
deferredProperties |
Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties |
disabled |
Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file. |
dom_id |
Get the actual DOM ID, which has been prefixed to make sure it’s unique. |
full |
Take every column of a layout, the same as span="all". Boolean rather than a bare
marker so it can be driven from content the way the rest of the template can -
full="@is_wide" resolves through the array manager like any other boolean attribute.
That does mean it needs a value: write full="true", since an empty
full="" resolves to false and removes the attribute again. Reflects for the same
reason grow does.
|
grow |
How much of a layout’s leftover space this widget should take. Only means anything inside a
container that has a layout (see Et2LayoutController): a bare grow or
grow="1" takes an equal share of whatever the non-growing children left over,
grow="2" takes twice what a grow="1" sibling does. It has to reflect.
The layout stylesheet matches the [grow] attribute - CSS cannot see a property - and
transformAttributes() only calls setAttribute() for an attribute the element already carries or a
property declared as reflecting. Widgets built from a .xet are created with
document.createElement() and handed their attributes as an object, so they carry none at that
point: without this declaration grow="1" lands as an inert JS property and nothing in
the layout ever matches it.
|
hidden |
The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way. |
id |
Get the ID of the widget |
label |
The label of the widget Legacy support for labels with %s that get wrapped around the widget Not the best way go with webComponents - shouldn’t modify their DOM like this |
noLang |
Disable any translations for the widget |
parentId |
Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location |
span |
How many of a layout’s columns this widget should take.
span="all" is every column wherever the widget landed, span="end" /
span="*" is from its own column to the end of its line. Only means anything inside a
container that has a layout, and only for the column layouts -
stack gives every child the full width anyway. The same name is also read straight
off the XML node by the legacy <grid> widget, for the unrelated job of counting
table cells to merge; that path never looks at the widget, so declaring it here does not disturb
it. Reflecting it does mean a legacy grid’s span="all" cells now carry the attribute
too, which matches nothing outside a layout. Reflects for the same reason grow does.
|
statustext |
Tooltip which is shown for this element on hover |
styles |
WebComponent * |
options |
Get property-values as object |
supportedWidgetClasses |
et2_widget compatability |
Et2InputWidget
| Name | Description |
|---|---|
autofocus |
Have browser focus this input on load. Overrides etemplate2.focusOnFirstInput(), use only once per page https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes |
hasFeedbackFor |
Get a list of feedback types |
translate |
List of properties that get translated Done separately to not interfere with properties - if we re-define label property, labels go missing. |
needed |
Compatibility for deprecated name “needed” |
LitElement
| Name | Description |
|---|---|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Events
| Name | Description | Event Detail |
|---|---|---|
focus |
Emitted when the editor receives focus. |
FocusEvent
|
blur |
Emitted when focus leaves the editor, including TinyMCE chrome and dialogs. |
FocusEvent
|
input |
Emitted when user input changes the editor value. |
Event
|
change |
Emitted when the user commits an editor value change. |
Event
|
Learn more about events.
Methods
| Name | Description | Arguments |
|---|---|---|
addToolbarItem()
|
Append a toolbar item to the computed toolbar for integrations that extend the editor UI before TinyMCE initializes. |
item: string
|
registerEditorSetupHook()
|
Register a TinyMCE setup hook for integrations that need to add custom UI such as toolbar buttons before the editor finishes initializing. |
key: string, hook: TinyMceSetupHook
|
unregisterEditorSetupHook()
|
Remove a previously registered TinyMCE setup hook. |
key: string
|
Learn more about methods.
Inherited methods (31)
Et2InputWidget
| Name | Description |
|---|---|
blur() |
Take focus away from whatever has it inside us. Blurring the host is not enough everywhere (Firefox): the focused node is in our shadow root, or in the one of a widget inside it. |
et2HandleBlur() |
If the value is unchanged, put any held validation messages back Named et2HandleBlur to avoid overwriting handleBlur() in Shoelace components |
et2HandleFocus() |
When input receives focus, clear any validation errors. If the value is the same on blur, we’ll put them back The ones from the server (ManualMessage) can interfere with submitting. Named et2HandleFocus to avoid overwriting handleFocus() in Shoelace components |
getInputNode() |
Get input to e.g. set aria-attributes |
getValue() |
Serialize the widget value, optionally normalizing rich-text content for submit. Mail clients often strip editor-level CSS, so users expect their preferred font and size to survive in the markup itself. This is not ideal, but it is easier to do here before submit than to do it server-side. |
handleSlChange() |
Handle sl-change event from Shoelace components and dispatch a change event so anything listening for change events can react to it instead of having to listen for both sl-change and change. |
isValid() |
Used by etemplate2 to determine if we can submit or not |
submit() |
Called whenever the template gets submitted. We return false if the widget is not valid, which cancels the submission. |
validate() |
Massively simplified validate, as compared to what ValidatorMixin gives us, since ValidatorMixin extends FormControlMixin which breaks SlSelect’s render() We take all validators for the widget, and if there’s a value (or field is required) we check the value with each validator. For array values we check each element with each validator. If the value does not pass the validator, we collect the message and display feedback to the user. We handle validation errors from the server with ManualMessages, which always “fail”. If the value is empty, we only validate if the field is required. |
_oldChange() |
Change handler calling custom handler set via onchange attribute |
Et2Widget
| Name | Description |
|---|---|
checkCreateNamespace() |
Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions |
clone() |
Creates a copy of this widget. |
createElementFromNode() |
Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node. |
getArrayMgr() |
Returns the array manager object for the given part |
getArrayMgrs() |
Returns an associative array containing the top-most array managers. |
getChildren() |
Get child widgets Use |
getInstanceManager() |
Returns the instance manager |
getPath() |
Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this |
getRoot() |
Returns the base widget Usually this is the same as getInstanceManager().widgetContainer |
loadFromXML() |
Loads the widget tree from an XML node |
loadingFinished() |
Needed for legacy compatability. |
parseXMLAttrs() |
The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes. |
set_label() |
NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template |
setArrayMgr() |
Sets the array manager for the given part |
setArrayMgrs() |
Sets all array manager objects - this function can be used to set the root array managers of the container object. |
setInstanceManager() |
Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference |
_handleClick() |
Click handler calling custom handler set via onclick attribute to this.onclick |
destroy() |
et2_widget compatability |
set_class() |
Set the widget class |
set_disabled() |
Wrapper on this.disabled because legacy had it. |
set_statustext() |
supports legacy set_statustext |
Parts
| Name | Description |
|---|---|
form-control |
The form control wrapper containing label, editor, and help text. |
form-control-input |
The editor wrapper. |
readonly-content |
The readonly value container when readonly is set. |
markdown-shell |
Wraps source and preview, only when markdown is on in ascii mode. |
markdown-view |
The edit / split / preview switcher, one of the field controls. |
field-controls |
The strip over the top-right corner holding the view switcher and anything slotted into field-controls. Rendered in every mode. |
markdown-preview |
The rendered markdown pane. |
markdown-popup |
The format popup shown over a selection. |
Learn more about customizing CSS parts.