Now.js Framework Documentation

Now.js Framework Documentation

DateElementFactory

EN 18 Nov 2026 02:27

DateElementFactory

EmbeddedDateTime A hand-built date/time picker that replaces the native <input type="date"> and friends, so the calendar UI looks and behaves the same across browsers. Supports date, time and datetime-local modes. Instantiated once per element by DateElementFactory; the original input is hidden but kept so the form still submits its value.

Generated from source on 2026-08-21. Descriptions come from JSDoc in the file.
Re-run docs_scaffold when the code changes; hand edits are lost on regeneration

Source

  • File: Now/js/DateElementFactory.js (1915 lines)
  • Form: ES class

Public methods (17)

applyRangePreset(key)

Sets the range to a preset (today, yesterday, 7d, 30d, thismonth, lastmonth, thisyear) and closes the picker. Range mode only.

close()

Close the picker dropdown. Delegates to the shared DropdownPanel, which triggers the picker's own close callback.

static create(def)

Create a date field from a definition (ElementManager.create()). The input gets its type here ('date', 'datetime-local'; 'daterange' is a date input in range mode), because the picker takes its mode from that type.

static createInstance(element, config = {})

Get or create the element's instance state, same as the base ElementFactory.

destroy()

Tear the picker down: close it if open and remove its locale listener.

getDate()

The currently selected date.

getElement()

The wrapper element this picker rendered into.

getRange()

The two sides of a range picker: {start, end}, '' for an empty side, or null when the picker is not in range mode.

getValue()

The value currently stored for form submission.

nextMonth()

Advance the visible calendar by one month, rolling over into the next year.

open()

Open the picker dropdown. Ignored while the field is disabled, read-only, or already open. For a time-only picker the calendar grid is hidden and only the time controls show.

previousMonth()

Step the visible calendar back one month, rolling over into the previous year.

selectDate(date)

Choose a date, combining it with the current time for datetime-local mode.

setValue(value)

Set the picker's value programmatically. An empty value clears both the date and time state, not just the display.

setRange(start, end)

Sets both sides of a range picker without announcing a change (loading saved state is not an edit). An end before the start is swapped.

static setupElement(instance)

Replace the native date input with an EmbeddedDateTime picker. A definition given to ElementManager.create() reaches the picker as the attributes it reads: rangeEnd (data-range-end), rangePresets, rangeMaxDays, min and max.

toggle()

Open the picker if closed, close it if open.

Language

Day and month names follow I18nManager's current locale; when there is none yet (i18n disabled, or before
Now.init() has loaded the translations), <html lang>, then en. Utils.date.getLocale() and CalendarManager use the same order.

Events

These are DOM CustomEvents dispatched on the element, so listen with
element.addEventListener() and read the values from event.detail.

Event When Triggered event.detail
gdatetime:open The picker opened {type, value}
gdatetime:change A date or time was picked {type, value, date}
gdatetime:close The picker closed {type, value}
gdatetime:rangechange A range picker settled on a new range (bubbles) {start, end, names: {start, end}}
element:change The element value changed {elementId, value, type}

Date range

A date input with data-range-end is a range picker: it holds the start, the
named input holds the end, and one calendar sets both. Either side may stay
empty.

<form data-form="report">
  <span class="form-control icon-calendar">
    <input type="date" name="from" data-range-end="to"
           data-range-presets="today,7d,thismonth" data-range-max-days="92">
  </span>
</form>
  • The end input is the field of that name in the same form (use
    <input type="hidden" name="to"> to bind it with data-attr); without one,
    a hidden input is created beside the start. Both are submitted under their
    own names.
  • From / To tabs pick the side the next day goes to; × empties that side.
    The first day is the start, the second the end and closes the picker; a day
    before the start becomes the start.
  • data-range-presets adds preset buttons; data-range-max-days disables
    days further than that from the start while the end is picked.
  • One change per range, when the picker closes: change on the end input
    when it changed, change on the start input, then gdatetime:rangechange.
  • Created in code: ElementManager.create('daterange', {name: 'from', rangeEnd: 'to', rangePresets: '7d,30d', rangeMaxDays: 31, onChange}).
    TableManager builds its data-type="daterange" column filter this way.

min / max compare calendar days, so the min day itself can be picked in
every time zone. onChange in a definition is called on every change, as for a
select.

Data attributes used

data-display-format · data-format · data-range-end · data-range-max-days · data-range-presets · data-show-seconds

Depends on

DropdownPanel · ElementFactory · ElementManager · EventManager · Utils