2

I'm trying to figure out a way, but cannot seem to find, how to set the load value of a Tempus Dominus datetimepicker field.

I have seen the options available here: https://tempusdominus.github.io/bootstrap-4/Options/#format

At the moment when the field has a value selected, it returns the value 02/13/2019 1:37 PM. But if say, I'm editing a record, I want to be able to edit the value using the field, but all it does is open in blank at the moment.

I store my particular field in as a timestamp in MySQL so like YYYY-MM-DD HH:MM:SS, so I am wondering, is there a way to set the loaded date and time to my field?

Matthew
  • 1,565
  • 6
  • 32
  • 56

1 Answers1

3

Having had the same issue using Django I implemented the following solution:

At the bottom of the page (after initiating the temups dominus datepicker) have a function like:

function pasteDate() {
    $('#datetimepicker1').datetimepicker('date', moment('{{ form.date_weekday.value }}, {{ form.date.value|date:"d.m.Y" }}', 'dddd, DD.MM.YYYY'));
}

And run it AFTER (setTimeout for 10 milliseconds) the page has fully loaded and thus initiated and formatted the datepicker according to your setup:

window.onload = setTimeout("pasteDate()", 10);

In this example my tempus dominus datepicker looks like this:

$(function() {
  $("#datetimepicker1").datetimepicker({
    minDate: new Date(),
    format: 'dddd, DD.MM.YYYY'
  });
});
Aaron Scheib
  • 358
  • 4
  • 18