Skip to main content Skip to docs navigation

Functions

On this page
For the sake of the following documentation, assume there's a picker setup like this:
const picker = new tempusdominus
    .TempusDominus(document.getElementById('datetimepicker1'));

updateOptions(object, boolean?)

In previous version there was a function to read/write to each of the provided options. This made it easy to use but made the code bulky and harder to maintain. updateOptions replaces those functions and takes an object of new options. This allows for multiple options to be set at the same time and works the same way as when setting up the picker.

If the optional reset flag is provided then new options will be merged with the default values.

dispose

Destroys the widget and removes all attached event listeners. If the picker is open it will be hidden and the event fired.

disable

Disables the input element and the component is attached to, by adding a disabled="true" attribute to it. If the widget was visible before that call it is hidden.

Emits

  • Namespace.events.hide - if the widget was visible before this call

enable

Enables the input element and the component is attached to, by removing disabled attribute from it.

clear

Clears all selected dates. This is a short cut to picker.dates.clear()

subscribe(event | events[], callback | callbacks[])

Instead of adding event listeners to the pickers element, you can use the subscribe method. You can provide a single event to listen for or an array of events. When providing an array the number of callbacks must be the same as the number of events.

The subscribe method returns an unsubscribe method or an array of methods if multiple events are provided. Calling unsubscribe remove the callback from the event listeners. Unsubscribing will not prevent addEventListener() from working.

const subscription = picker.subscribe(tempusdominus.Namespace.events.change, (e) => {
  console.log(e);
});

// event listener can be unsubscribed to:
subscription.unsubscribe();

//you can also provide multiple events:
const subscriptions = picker.subscribe(
        [tempusdominus.Namespace.events.show,tempusdominus.Namespace.events.hide],
        [(e)=> console.log(e), (e) => console.log(e)]
)