Link To
<et2-link-to> | Et2LinkTo
Overview
Choose an existing entry, VFS file or local file, and link it to the current entry.
If there is no “current entry”, link information will be stored for submission instead of being directly linked.
What it is for
The widget that creates links. It is a row of four ways to attach something to the current entry:
upload a local file, pick a file out of the VFS, paste files from the EGroupware file clipboard, or search
for an existing entry and link that. The search half is an
<et2-link-entry>; the “Link” button beside it appears once something is selected.
See Choosing a link widget for how it relates to the rest of the family.
It is also the upload widget that does not have to be told where files go. Whatever is uploaded here becomes
an attachment of the current entry (/apps/<app>/<id>/), and if that entry has no ID
yet the uploads are kept in the widget’s value until it gets one. Prefer it over
<et2-vfs-upload>, which needs a destination path and silently drops files into a temporary directory without one, whenever
you cannot name a VFS path or the entry is not saved yet. Use
<et2-file> only when the files are not going into the
VFS at all.
The Links tab
<et2-link-to> only creates links, it never shows them. The standard pairing is an
<et2-link-list> with the same id directly below it, which
shows what is there and lets the user remove it again:
<et2-link-to id="link_to" span="all"></et2-link-to>
<et2-link-list id="link_to" span="all"></et2-link-list>
Not live. Every path through this widget ends in a server request - Link::ajax_link to create
the link, Link::ajax_link_search to find an entry, a directory listing to pick a VFS file -
and this documentation site has no server to answer them. Everything below describes the behaviour against
a running EGroupware.
Value
The value names the entry that links are attached to, not the links themselves:
{to_app: "infolog", to_id: "7"}
to_id being a plain ID means the entry exists, and links are created on the server the moment
the user clicks “Link” - an uploaded file is attached to the entry right then. If the entry has not been
saved yet there is nothing to link to, so to_id is instead an object collecting the links
(uploaded files included, as temporary files). They are submitted with the form, and the application turns
them into real links and attachments once it has saved the entry and knows its ID:
Api\Link::link('myapp', $new_id, $content['link_to']['to_id']);
The widget switches between the two on its own - a template does not have to care, as long as the server put the entry’s app and ID in the content.
Limiting what can be linked
onlyApp restricts the search to one application and hides the application selector.
applicationList allows a comma separated set of them instead.
<et2-link-to id="link_to" onlyApp="addressbook"></et2-link-to>
<et2-link-to id="link_to" applicationList="addressbook,infolog"></et2-link-to>
Knowing when a link was made
After a successful link the widget clears itself and fires et2-change, whose
detail is the array of links that were just created. That is how
<et2-link-list> updates itself without asking the server again:
this.et2.getWidgetById("link_to").addEventListener("et2-change", (e) =>
{
console.log("linked", e.detail);
});
It also fires the older link.et2_link_to event with the raw server result, which existing
application code still listens for.
In the other direction it listens for et2-delete from any <et2-link-list> in
the same template, so that removing a link from a not-yet-saved entry also removes it from what will be
submitted.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
applicationList
|
Limit to the listed applications (comma seperated) |
string
|
null
|
|
noFiles
|
Hide buttons to attach files |
boolean
|
false
|
|
onlyApp
|
Limit to just this application - hides app selection |
string
|
null
|
|
validationTypes
|
Types of validation supported by this FormControl (for instance ‘error’|‘warning’|‘info’) |
ValidationType[]
|
- |
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 |
|---|---|---|
et2-change |
Missing description |
CustomEvent
|
link.et2_link_to |
Missing description |
CustomEvent
|
change |
Missing description |
Event
|
Learn more about events.
Methods
| Name | Description | Arguments |
|---|---|---|
createLink()
|
Create links Using current value for one end of the link, create links to the provided files or entries |
_links: LinkInfo[]
|
handleEntryCleared()
|
An entry was selected, but instead of clicking “Link”, the user cleared the selection |
event:
|
handleEntrySelected()
|
An entry has been selected, ready to link |
event:
|
handleLinkDeleted()
|
Handle a link being removed Event is thrown every time a link is removed (from a LinkList) but we only care if the entry hasn’t been saved yet and has no ID. In this case we’ve been keeping the list to submit and link server-side so we have to remove the deleted link from our list. |
e: CustomEvent
|
resetAfterLink()
|
A link was attempted. Reset internal values to get ready for the next one. | - |
_link_result()
|
Sent some links, server has a result |
success: Object
|
Learn more about methods.
Inherited methods (29)
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 |
Et2InputWidget
| Name | Description |
|---|---|
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 |
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 |
Belongs to
Related
These widgets are related by naming but not by inheritance or sub-widget composition.