tempus-dominus: Trigger "change" Events of Input Element

For example, if we use the Simple Setup (jQuery) where the input element has an input group and has a jQuery event attached by:

$("#datetimepicker1Input").on("change", () => alert('something'));

then we convert the input to datetime picker by:

new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'));

The original “change” event of the input will not be fired unless the original event is attached to the div#datetimepicker1 and the event name is “change.td”.

It would be more convenient if the datetime picker can trigger the input’s original events. This can be done by:

  1. Change the event type from “change.td” to “change” before triggering the original events (either jQuery event or native HTML element event)
  2. Fire the event attached to the input element (not the enclosing DIV)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 17 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Either the user changes the input manually, or the user changes the input value by the datetime picker, the same plain old “change” event should be fired. Of course, if the user choose to add another listener to the datetime picker’s “changed.td”, it should be also fine. I believe this should be the most common usage of the date timer picker. Thank you for considering this.

But the point of this issue was to trigger the ORIGINAL (non namespaced) events (i.e… “change”) already added to the input element (before tempusDominus.TempusDominus is created) so users do not need to add handlers for the namespaced (“change.td”) event. (Please refer to the first post.)

The events are namespaced. You’re looking for change.td

It does not work as expected. e.g.

document
  .getElementById('datetimepicker1Input')
  .addEventListener('change', () => alert('change event fired'));

new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'), {
  //put your config here
});

The change event is only fired when the input loses focus, not fired after the datetime picker changes the data and close the calendar.

Note: It should also works for jQuery, e.g.

$('#datetimepicker1Input').on('change', () => alert('jQuery change event fired'));

new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'), {
  //put your config here
});

Ok I see. Let me play with it and see what I can do.

The outcome you’d like to see is that if the picker is attached to an input field and a user changes the input value that there should be a plain old change event on the field e.g. step 1 right?