Toolbar
<et2-toolbar> | Et2Toolbar
Overview
Toolbar shows inputs in a horizontal line. Inputs that do not fit are hidden in a dropdown.
The user can choose which inputs are shown. Inputs that do not fit are hidden. If the toolbar has an ID, the user’s choice of which inputs to hide is remembered as a preference.
<et2-toolbar>
<et2-button-icon image="balloon" label="Balloon"></et2-button-icon>
<et2-button-icon image="text-left">Left</et2-button-icon>
<et2-button-icon image="text-center">Center</et2-button-icon>
<et2-button-icon image="text-right">Right</et2-button-icon>
<sl-button-group label="History">
<et2-button-icon id="undo" image="arrow-counterclockwise" label="Undo"></et2-button-icon>
<et2-button-icon id="redo" image="arrow-clockwise" label="Redo"></et2-button-icon>
</sl-button-group>
<sl-button-group label="Formatting">
<et2-button-icon id="bold" image="type-bold" label="Bold"></et2-button-icon>
<et2-button-icon id="italic" image="type-italic" label="Italic"></et2-button-icon>
<et2-button-icon id="underline" image="type-underline" label="Underline"></et2-button-icon>
</sl-button-group>
</et2-toolbar>
Children
Toolbar is a container like Box, so it can have any child. Some children do not make sense, but most inputs will work.
The value of any child widgets will be returned if the form is submitted.
<et2-toolbar id="child_example" preferenceApp="docs">
<et2-button-icon id="add" image="circle-plus" label="Add" noSubmit onClick="alert('Add clicked')"></et2-button-icon> <et2-searchbox id="search"></et2-searchbox>
<et2-button-toggle id="notification" label="Notification" icon="bell-fill"></et2-button-toggle>
<et2-switch id="database" label="Delete database"></et2-switch>
<et2-switch-icon id="holidays" label="Have holidays" onIcon="check" offIcon="x"></et2-switch-icon>
<et2-dropdown-button label="Some checkboxes">
<et2-checkbox id="check_a" label="Checkbox A"></et2-checkbox>
<et2-checkbox id="check_b" label="Checkbox B"></et2-checkbox>
<et2-checkbox id="check_c" label="Checkbox C"></et2-checkbox>
</et2-dropdown-button>
<et2-box>
No ID, just text
</et2-box>
</et2-toolbar>
<script>
document.addEventListener("DOMContentLoaded", () => {
const toolbar = document.getElementById("child_example");
toolbar.addEventListener("sl-change", (e) => {
alert(e.target.dom_id + " changed to " + e.target.value);
});
});
</script>
Actions
Any actions set for a toolbar will be turned into inputs. Toolbar will not have a context menu. If the form
is submitted, the ID of the last action will be returned under <toolbar#id>["action"]
Slots
Name | Description |
---|---|
(default) | Toolbar contents |
list
|
Toolbar contents that start hidden in the dropdown |
Learn more about using slots.
Properties
Name | Description | Reflects | 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
|
Overridden from parent because toolbar can turn actions into buttons |
object
|
- | |
align
|
Used by Et2Box to determine alignment. Allowed values are left, right |
|
string
|
- |
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 |
|
boolean
|
- |
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. |
|
string
|
- |
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
|
- | |
groupChildren
|
Actions with children should be shown as dropdown (true) or flat list (false) |
boolean
|
false
|
|
hasFeedbackFor
|
Get a list of feedback types |
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 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 |
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 |
string
|
- | |
preferenceApp
|
Define a custom preference application for saving the toolbar preferences. This is useful when you have the same toolbar and you use it in multiple places, which have different application names. When not set it defaults to the result of this.egw().app_name(); |
string
|
""
|
|
preferenceId
|
Define a custom preference id for saving the toolbar preferences. This is useful when you have the same toolbar and you use it in a pop up but also in a tab, which have different dom ids. When not set it defaults to the dom id of the toolbar. |
string
|
""
|
|
statustext
|
Tooltip which is shown for this element on hover |
|
string
|
- |
styles
|
WebComponent * | - | - | |
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”
use required instead |
- | - | |
options
|
Get property-values as object
use widget methods |
object
|
- | |
readOnly
|
Lion mapping
true |
- | - | |
supportedWidgetClasses
|
et2_widget compatability
Legacy compatability. Some legacy widgets check their parent to see whats allowed |
array
|
[]
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
et2-resize |
Emitted when the toolbar re-lays out | - |
Learn more about events.
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:
|
et2HandleBlur()
|
If the value is unchanged, put any held validation messages back Named et2HandleBlur to avoid overwriting handleBlur() in Shoelace components |
_ev: FocusEvent
|
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 |
_ev: FocusEvent
|
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 |
- |
getDetachedAttributes()
|
Code for implementing et2_IDetachedDOM Individual widgets are detected and handled by the grid, but the interface is needed for this to happen |
_attrs: array
|
getInputNode()
|
Get input to e.g. set aria-attributes | - |
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 | - |
handleChange()
|
Handle changes on child widgets - call action when appropriate |
e: Event
|
handleClick()
|
Handle clicks on child widgets - call action when appropriate |
e: Event
|
handleSettingsClose()
|
Update preference, reset if requested |
button_id: , value: , event: , e:
|
isValid()
|
Used by etemplate2 to determine if we can submit or not |
messages:
|
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
|
submit()
|
Called whenever the template gets submitted. We return false if the widget is not valid, which cancels the submission. |
_values:
|
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. |
skipManual:
|
_addAction()
|
Take a single action and turn it into an input, placing it inside parent Handles actions with children |
action: EgwAction, parent:
|
_get_action_links()
|
Get all action-links / id’s of 1.-level actions from a given action object This can be overwritten to not allow all actions, by not returning them here. |
actions:
|
_handleClick()
|
Click handler calling custom handler set via onclick attribute to this.onclick |
_ev: MouseEvent
|
_labelTemplate()
|
Common sub-template to add a label. This goes inside the form control wrapper div, before and at the same depth as the input controls. | - |
_link_actions()
|
Link the actions to the DOM nodes / widget bits. |
actions: object
|
_makeInput()
|
Make an input based on the given action, adds it to parent element Handles just actions, manages common setup |
action: Object, parent: HTMLElement
|
_oldChange()
|
Change handler calling custom handler set via onchange attribute |
_ev: Event
|
_organiseChild()
|
Slot a child according to preference and available space |
child: HTMLElement
|
_organiseChildren()
|
Adjust the location of child inputs without destroying / re-creating them | - |
_parseActions()
|
Parse a list of actions and create matching inputs into the toolbar |
actions: EgwAction[] | { [id : string] : object }
|
_set_label()
|
Do some fancy stuff on the label, splitting it up if there’s a %s in it Normally called from updated(), the “normal” setter stuff has already been run before this is called. We only override our special cases (%s) because the normal label has been set by the parent |
value: string
|
_setAriaAttributes()
|
Set aria-attributes on our input node | - |
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
|
Learn more about methods.