Widget
Et2Widget
Overview
Et2Widget is the mixin every eTemplate widget is built from. It is what turns a plain
Lit
element into something an eTemplate can create, address, fill with content and destroy - so almost
everything in the Properties table below appears on every widget in this reference, and is documented here
rather than repeated on all of them.
export class Et2Example extends Et2Widget(LitElement) { … }
An input additionally uses Et2InputWidget, which layers value handling and validation on top of this.
What it provides
Identity. id is the widget’s name inside its template, and is what the server
sends values back under. dom_id is the resulting DOM id, which is namespaced by the template so
two templates on one page cannot collide.
Content binding. A widget does not usually carry its own value in the template - it names
one, and the surrounding content supplies it. getArrayMgr() and the array managers reachable
from it are how a widget resolves @-references and ${row} expressions against the
content, the select options, the modifications and the validation errors the server sent.
Beware the namespace rule: putting an id on a container opens a namespace for
everything inside it, so children resolve their references relative to that id. Giving a layout box an id it
does not need silently starves its whole subtree - references go falsy and auto-repeating grids stop
repeating, with nothing logged.
The widget tree. getChildren(), getRoot(),
getPath() and getInstanceManager() navigate the eTemplate structure, which is not
the same as the DOM tree - a row widget in a datagrid, for instance, has no widget-tree parent at all.
Construction from XML. loadFromXML(), createElementFromNode() and
parseXMLAttrs() are how a .xet template becomes live widgets. You call these only
when building something that hosts its own template; ordinary widgets get them for free.
Presentation. label, class, statustext (the
tooltip), align, accesskey and hidden.
Actions. actions attaches the egw action system - context menus, drag and
drop, keyboard shortcuts.
disabled is not what you expect
Et2Widget’s own style is:
:host([disabled]) { display: none; }
Only Et2InputWidget puts that back to
display: initial. So on an input, disabled greys the widget out as you would
expect - but on anything else, a box, a groupbox, et2-details, a tab,
disabled removes the widget from the page entirely and is indistinguishable from
hidden.
Use hidden when you mean “not visible”, so the template says what it means. See
Disabled vs Readonly vs Hidden.
Lifecycle
loadingFinished() runs once the widget and its children are constructed and bound to content -
it is the point at which the widget tree is complete, and the right place for work that needs to see
siblings. destroy() tears the widget down and detaches it from its parent.
For the standard Lit lifecycle underneath this - connectedCallback, willUpdate,
firstUpdated, updated - see
Lit’s own documentation. A practical consequence worth knowing: a widget is constructed as soon as it is inserted into
the document, but its render root does not exist until the first update, so anything reaching into a widget
from outside has to wait for updateComplete.
Writing one
See Creating a widget for a worked example, and Web Component Authoring for the conventions this codebase expects - including how to document what you write.
Used by
This mixin is applied by the following widgets.
- Ai
- App Box
- Avatar
- Avatar Group
- Badge
- Box
- Button Copy
- Category Box
- Customfields Header
- Datagrid
- Description
- Details
- Dialog
- Dropdown
- Favorites Menu
- File Item
- Historylog
- Historylog Status
- Historylog Value
- Html
- Iframe
- Image
- Link
- Link String
- Menu Item
- Merge Dialog
- Nextmatch
- Nextmatch Header
- Portlet
- Spinner
- Split
- Styles
- Tab
- Tab Panel
- Tag
- Template
- Vfs Select Row
- Vfs Size
- Visually Hidden
Properties
| Name | Description | Type | Default |
|---|---|---|---|
accesskey |
Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character. |
string
|
- |
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 |
string
|
- |
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 |
string
|
- |
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. |
boolean
|
false
|
dom_id |
Get the actual DOM ID, which has been prefixed to make sure it’s unique. |
string
|
- |
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. |
boolean
|
- |
id |
Get the ID of the widget |
string
|
- |
label |
The label of the widget This is usually displayed in some way. It’s also important for accessability. This is defined in the parent somewhere, and re-defining it causes labels to disappear |
string
|
- |
noLang |
Disable any translations for the widget |
boolean
|
- |
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 | - | - |
statustext |
Tooltip which is shown for this element on hover |
string
|
- |
styles |
WebComponent * | - | - |
options |
Get property-values as object
use widget methods |
object
|
- |
supportedWidgetClasses |
et2_widget compatability
Legacy compatability. Some legacy widgets check their parent to see whats allowed |
array
|
[]
|
Methods
| Name | Description | Arguments |
|---|---|---|
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. |
_parent: et2_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. |
_node: , _name:
|
getArrayMgr()
|
Returns the array manager object for the given part |
managed_array_type: string
|
getArrayMgrs()
|
Returns an associative array containing the top-most array managers. |
_mgrs: object
|
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 |
_node:
|
loadingFinished()
|
Needed for legacy compatability. |
promises: Promise[]
|
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. |
_attrsObj: , _target: object, _proto: et2_widget
|
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 |
value: string
|
setArrayMgr()
|
Sets the array manager for the given part |
_part: string, _mgr: object
|
setArrayMgrs()
|
Sets all array manager objects - this function can be used to set the root array managers of the container object. |
_mgrs: 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 |
manager: etemplate2
|
_handleClick()
|
Click handler calling custom handler set via onclick attribute to this.onclick |
_ev: MouseEvent
|
destroy()
|
et2_widget compatability
true |
- |
set_class()
|
Set the widget class
Use this.class or this.classList instead |
new_class: string
|
set_disabled()
|
Wrapper on this.disabled because legacy had it.
Use widget.disabled for visually disabled, widget.hidden for visually hidden. Disabled vs Readonly vs Hidden |
value: boolean
|
set_statustext()
|
supports legacy set_statustext
use this.statustext |
value: string
|