Search code examples
jquerydatetimepicker

Trent Richardson inline DateTimePicker defaultValue always shows 00:00 on alt field


below is my jquery code for initialising the dateTimePicker, but the documentation for the DefaultValue is sparse, as is the AltField documentation, so this is my best guess, but clearly isn't working, and always the time portion is showing 00:00 in the AltField :

$("#dateTimeField").datetimepicker({
    dateFormat: 'dd.mm.yy',
    altTimeFormat: 'HH:mm',
    firstDay: 1, showTime: false,
    hourText: "tunti",
    minuteText: "min",
    altField: "#TextBox1",
    altFieldTimeOnly: false,
    showButtonPanel: false,
    defaultValue: '23:59', // default time
    defaultDate: -5,

});

The documentation for this 'defaultValue' option simply states:

defaultValue : Default: null - String of the default time value placed in the input on focus when the input is empty.

The normal jQuery defaultDate option is showing correctly in the altField, but I need to show a default time of 23:59 also in the field.

Can anyone spot what I'm missing?


Solution

  • Finaly the solution wasn't that complicated.

    Consider using "hour" and "minute" option to solve your problem.

    hour :
        Default: 0 - Initial hour set.
    
    minute :
        Default: 0 - Initial minute set.
    

    Finally you'll have something like that :

    $("#dateField").datetimepicker({
        dateFormat: 'dd.mm.yy',
        altTimeFormat: 'HH:mm',
        firstDay: 1, showTime: false,
        hourText: "tunti",
        minuteText: "min",
        altField: "#altField",
        altFieldTimeOnly: false,
        showButtonPanel: false,
        hour: 23,
        minute: 59, // default time
        defaultDate: -5,
    });
    

    Here is a WORKING FIDDLE that initalise time to "23:59" and day to "-5".

    Hope it helped you.