2

I'm using the Tempus Dominus plugin for bootstrap 4. When i set the date/time using the picker icon and then submit it works fine. If i manually change the date/time via direct entry in the text box it visually updates, but when i submit its the original default value.

        var dateFormat = "DD-MM-YYYY HH:mm:ss";
        var CurrDateMin = "01-01-2000 00:00:00";
        var CurrDateMax = "18-01-2038 23:59:59";
        var MinDate = "01-01-2000 00:00:00";
        var MaxDate = "18-01-2038 23:59:59";

        dateCurrMin = moment(CurrDateMin, dateFormat);
        dateCurrMax = moment(CurrDateMax, dateFormat);
        dateMin = moment(MinDate, dateFormat);
        dateMax = moment(MaxDate, dateFormat);



        $(function () {

            $('#CdatetimepickerFrom').datetimepicker({
                'format': dateFormat,
                'date': moment("01-01-2000 00:00:00", dateFormat),
                'minDate': dateMin,
                'maxDate': dateMax,
                'current': false
            });

            $('#CdatetimepickerTo').datetimepicker({
                'format': dateFormat,
                'date': moment("18-01-2038 23:59:59", dateFormat),
                'minDate': dateMin,
                'maxDate': dateMax,
                'current': false
            });

        });

I'm submitting by ajax request:

 var params = {
                "validFrom": moment($('#CdatetimepickerFrom').datetimepicker('date')).unix(),
                "validTo": moment($('#CdatetimepickerTo').datetimepicker('date')).unix(),
              };

EDIT: After hours spent on this i figured out i should be using 'viewDate' and not 'date' when reading the value of the datetime picker.

A Houghton
  • 372
  • 5
  • 18
  • Did you find a solution? I have a similar thread: https://stackoverflow.com/questions/74805638/tempus-dominus-datetimepicker-for-bootstrap-4-manual-input-of-date-through-ke But I'm already using `viewDate`, and it's still not setting correctly from the keyboard. – gene b. Dec 15 '22 at 01:17

1 Answers1

0

if manual input error in tempusdominus-bootstrap-4.min.js

  1. find _getLastPickedDate()

  2. replace with var lastDate = this._dates[this._getLastPickedDateIndex()]; if (typeof lastDate == "undefined" || lastDate == null) { lastDate = this.getMoment(); } return lastDate;

udorb b
  • 135
  • 3