Vanilla Date/Time picker.
install via npm, along with required libraries:
npm install --save lddatetimepicker @loadingio/debounce.js dayjs
include required js / css:
<link rel="stylesheet" type="text/css" href="dist/index.min.css">
<script type="text/javascript" src="path-to/debounce.js"></script>
<script type="text/javascript" src="path-to-day.js"></script>
<script type="text/javascript" src="dist/index.min.js"></script>
initialize:
lddtp = new lddatetimepicker({host: "input"})
lddtp.value("2021/01/23"); // set value
lddtp.value(); // get value
Constructor options:
host: host element ( should be an input element, if provided )time: default true. hide and disable time picker if false.viewMode: default false. if true, a prettified, read-only overlay is rendered right on top of the host input, showing the picked value as2011/01/01 13:05 UTC+8( date only iftimeis false ). the host input still carries the raw ISO value, so form submission is unaffected. the overlay steps aside whenever host is focused, so the raw value stays editable by typing, and comes back on blur. requireshost.suppress: default false. suppress popup when clicking host if true.fixed: (deprecated) default false. true to enabled fixed mode.mode: eitherin-place,out-placeorfixed.fixed:- when toggled, the datetime widget pops up in screen center, and covers the whole screen.
- will be forced to true if
hostandcontainerare not provided.
out-place: widget is inserted under body.in-place: widget is inserted afterhost.
container: optional. if provided,lddatetimepickerare rendered barely in this container.- this should be an object with following fields:
node: required. container element.toggle(v): required. function for toggling container on / off.isOn(): required. return true if a container is toggled on, otherwise false.position({x,y,ix,iy}): optional. use this function to correctly position container.x: suggested x positiony: suggested y positionix: suggested x position if mode isin-place.iy: suggested y position if mode isin-place.
- by default, mode will be
out-placewithcontaineroption set.- Set
modetofixedif the container is a fixed element (such as dialog)
- Set
- this should be an object with following fields:
zmgr: optional. if provided, widget will be auto z-indexing based on this zmgr.
isOn(): return true if lddatetimepicker dialog is on, otherwise return falsefire(n, ...args)on(n, cb)update()value()config(opt): update configuration.- following options are supported:
suppress: see constructor option for this option.time: see constructor option fortimeviewMode: see constructor option forviewMode
- return current config (
suppress,viewModeandtime) when calling without option.
- following options are supported:
MIT