Date
<et2-date> | Et2Date
Examples
et2-date is one day, picked from a calendar. No time of day: whatever time you put in, midnight
comes back out.
Which date widget
The date family is seven widgets that all look similar and mean different things. Pick by what the field actually holds, not by what it looks like.
| Widget | Editable | Holds |
|---|---|---|
et2-date
|
yes | a single day |
et2-date-time
|
yes | a day and a time of day |
et2-date-timeonly
|
yes | a time of day, no day |
et2-date-duration
|
yes | a length of time (2 hours), not a point in time |
et2-date-range
|
yes | two days, or a named period like “This week” |
et2-date-since
|
no | how long ago a moment was (“5 days”) |
et2-date-time-today
|
no | a moment, shown as a time if it is today and a date if it is not |
The first three are the same widget with the calendar or the clock turned off, so everything below applies
to all three. et2-date-duration only shares the family name - it is a number with a unit beside
it, and has no calendar at all.
Each editable one also has a read-only twin (et2-date_ro, et2-date-time_ro,
et2-date-timeonly_ro, et2-date-duration_ro) that renders text instead of an input.
You rarely write those yourself: when a template says readonly="true", eTemplate swaps in the
_ro widget for you. See
Disabled vs Readonly vs Hidden.
Setting a value
value is a property, not an attribute, on all of the editable date widgets - a
value="…" in plain HTML is ignored. In a template that makes no difference, because the
template reader assigns the property for you; in the examples on this page it means a small script.
The setter takes anything new Date() understands: the server’s own
Y-m-dTH:i:00Z strings, a Date, or milliseconds since the epoch.
<et2-date id="date-basic" label="Start date"></et2-date>
<script>
const dateBasic = document.getElementById("date-basic");
customElements.whenDefined("et2-date")
.then(() => dateBasic.updateComplete)
.then(() => {dateBasic.value = "2026-03-17T00:00:00Z";});
</script>
Value in, value out
What is displayed and what is submitted are two different strings. The field shows the date the way the
user’s dateformat preference says (Y-m-d on this site), while
value stays the machine-readable Y-m-dT00:00:00Z no matter which preference is
set. Pick a different day from the calendar below and watch both.
Do not read that trailing Z as UTC. Throughout the date family the string is the time on the
user’s own clock - put 14:35 into an
et2-date-time and 14:35 is what comes back
out of it, wherever the user happens to be. The server, which knows the user’s timezone, is what turns it
into an instant.
Value: -
<et2-date id="date-value" label="Pick a day"></et2-date>
<p>Value: <span id="date-value-out">-</span></p>
<script>
const dateValue = document.getElementById("date-value");
const dateValueOut = document.getElementById("date-value-out");
const showDateValue = () => {dateValueOut.textContent = JSON.stringify(dateValue.value);};
dateValue.addEventListener("change", showDateValue);
customElements.whenDefined("et2-date")
.then(() => dateValue.updateComplete)
.then(() => {
dateValue.value = "2026-03-17T00:00:00Z";
showDateValue();
});
</script>
Only the day survives
A value with a time in it is accepted and then flattened to midnight, because that is all an
et2-date can represent. If the time matters, the field wanted
et2-date-time.
Value: -
<et2-date id="date-strip" label="Set to 14:35"></et2-date>
<p>Value: <span id="date-strip-out">-</span></p>
<script>
const dateStrip = document.getElementById("date-strip");
const dateStripOut = document.getElementById("date-strip-out");
customElements.whenDefined("et2-date")
.then(() => dateStrip.updateComplete)
.then(() => {
dateStrip.value = "2026-03-17T14:35:00Z";
dateStripOut.textContent = JSON.stringify(dateStrip.value);
});
</script>
Clearing
Empty, 0 and "0" all mean “no date” - eTemplate content arrives as any of the
three - and all clear the field rather than landing on 1970. Clearing this way deliberately does
not fire change, so a filter that resets itself to empty cannot echo back into
whatever reset it.
<et2-date id="date-clear" label="Clearable"></et2-date>
<button type="button" id="date-clear-button">Clear</button>
<script>
const dateClear = document.getElementById("date-clear");
document.getElementById("date-clear-button").addEventListener("click", () => {dateClear.value = 0;});
customElements.whenDefined("et2-date")
.then(() => dateClear.updateComplete)
.then(() => {dateClear.value = "2026-03-17T00:00:00Z";});
</script>
Limiting which days can be picked
min and max grey out everything outside the range. Unlike value they
are ordinary attributes, so a template sets them directly. minDate and maxDate are
the same two limits under the names the calendar uses, and either spelling works. Try to reach February
below.
<et2-date id="date-limits" label="March 2026 only"
min="2026-03-01T00:00:00Z" max="2026-03-31T00:00:00Z"></et2-date>
<script>
const dateLimits = document.getElementById("date-limits");
customElements.whenDefined("et2-date")
.then(() => dateLimits.updateComplete)
.then(() => {dateLimits.value = "2026-03-17T00:00:00Z";});
</script>
A limit can also be changed later, which is how a pair of fields keeps itself in order - moving the start date forward pushes the end date’s minimum with it.
<et2-date id="date-from" label="From"></et2-date>
<et2-date id="date-to" label="To"></et2-date>
<script>
const dateFrom = document.getElementById("date-from");
const dateTo = document.getElementById("date-to");
dateFrom.addEventListener("change", () => {dateTo.min = dateFrom.value;});
dateTo.addEventListener("change", () => {dateFrom.max = dateTo.value;});
</script>
Typing, and the arrows
The field is a normal text input as well as a calendar trigger: type a date in the format the field displays
- 2026-12-24 here - and it is parsed and the calendar follows along. Hover the field and two
arrows appear on its right hand end; they step a day at a time, and on an empty field the first press lands
on today rather than moving anywhere.
<et2-date label="Type it or step it"></et2-date>
Placeholder and disabled
placeholder is shown while the field is empty. disabled takes the field out of
play without changing what it holds.
<et2-date label="Due" placeholder="No due date"></et2-date>
<et2-date label="Locked" disabled></et2-date>
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
freeMinuteEntry
|
Allow value that is not a multiple of minuteIncrement eg: 11:23 with default 5 minuteIncrement = 11:25 16:47 with 30 minuteIncrement = 17:00 If false (default), it is impossible to have a time that is not a multiple of minuteIncrement. Does not affect scroll, which always goes to nearest multiple. |
boolean
|
false
|
|
inline
|
Display the calendar inline instead of revealed as needed |
boolean
|
- | |
max
|
Latest date the user is allowed to choose |
Date | ""
|
- | |
maxDate
|
Latest date the user is allowed to choose, or ”″ for no limit |
Date | ""
|
- | |
min
|
Earliest date the user is allowed to choose The same thing as minDate, under the name templates use. Flatpickr calls it minDate, the server-side widget calls it min, and both names have to work. |
Date | ""
|
- | |
minDate
|
Earliest date the user is allowed to choose, or ”″ for no limit Anything new Date() understands is accepted; something it cannot parse is treated as no limit rather than becoming an Invalid Date the calendar would choke on. The value has to be kept here rather than handed straight to Flatpickr: the calendar is not created until the widget is first shown (see init()), which is long after a template has set its limits, so getOptions() reads these back when it eventually does get built. |
Date | ""
|
- | |
placeholder
|
Placeholder text for input |
string
|
- | |
placement
|
The preferred placement of the calendar popup can be set with the placement attribute. The default is “auto”. Note that the actual position may vary to ensure the calendar remains in the viewport. Valid placements are “top”, “bottom” or “auto”. |
"top" | "bottom" | "auto"
|
- |
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 |
|---|---|---|
change |
Missing description |
Event
|
input |
Missing description |
Event
|
Learn more about events.
Methods
| Name | Description | Arguments |
|---|---|---|
findInputField()
|
Override from flatpickr - This is the node we tell flatpickr to use It must be an , flatpickr doesn’t understand anything else | - |
getOptions()
|
Override some flatpickr defaults to get things how we like it | - |
handleScroll()
|
Handle clicks on scroll buttons |
e:
|
increment()
|
Increment the current value |
delta: number, field: "day" | "hour" | "minute", roundToDelta: boolean
|
init()
|
Override parent to skip call to CDN | - |
set_max()
|
Set the maximum allowed date |
max: string | Date
|
set_min()
|
Set the minimum allowed date |
min: string | Date
|
_handleCalendarChange()
|
flatpickr’s onChange callback - fires for every real value change (a calendar pick, clear(), or a committed setDate() call from _handleInputChange), unlike _onReady’s one-off startup call straight into _updateValueOnChange. Dispatch our own “change” here so onchange=”″ template bindings see calendar picks too, not just typed-and-parsed input (which previously only fired “change” from within _handleInputChange itself). |
selectedDates: Date[], dateStr: string, instance: Instance
|
_handleInputChange()
|
Update the calendar when the input value changes Otherwise, user’s change will be overwritten by calendar popup when the input loses focus |
e: InputEvent
|
_handleShortcutButtonClick()
|
Handle click on shortcut button(s) like “Today” |
button_index: , fp:
|
_mobileInputType()
|
For mobile, we use a plain input of the proper type | - |
_updateValueOnChange()
|
Change handler setting modelValue for validation |
selectedDates: Date[], dateStr: string, instance: Instance, _ev:
|
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 |
Related
These widgets are related by naming but not by inheritance or sub-widget composition.