Open qiyq opened 7 years ago
I am having the same issue. html input
<input class="hours-operation" type="text" value="14:45" data-date-format="HH:ii"/>
It seems to happen around here in the bootsrap-datetimepicker.js:454
getDate: function () {
var d = this.getUTCDate();
if (d === null) {
return null;
}
return new Date(d.getTime() + (d.getTimezoneOffset() * 60000));
},
I am very new to javascript and don't fully understand this but it looks like getUTCDate() returns undefined, I assume it is suppose to take in a string argument, something like "2017-12-12 14:45", but when it receives just the time (ie. "14:45") it returns undefined.
if (d === null) {
return null;
}
this if statement is using strict comparison, and null and undefined are not the same. I removed one of the equal signs and it got rid off the error.
if (d == null) {
return null;
}
This allows you to continue without error, but this still does not populate the datetimepicker with the time in value="" attribute. Do I need to pass something special into the datetimepicker options?
$(function () {
var timepickers = $('input[class^="hours-operation"]');
$.each(timepickers, function(index, timepicker) {
$(timepicker).datetimepicker({
format: 'HH:ii P',
autoclose: true,
showMeridian: true,
Default: true,
pickDate: false,
startView: 1,
minView: 0,
maxView: 1,
});
});
$(".datetimepicker").prop("id", "datetime-container");
});
That's what I did:
if (!d) { return null; }
Do any of you have a workaround for populating with the correct object for time-only value?
@zanozik You have to build valid datetime, if you are only using it for time, then just use the epoch and change hours and minutes. It is more work than it should be but it gets the job done.
P.S. Repository is marked as deprecated.
@mirnes-cajlakovic Well, of course, I'm using it for time only - this is the source of the problem! So, the best thing we could come up with is to use a fully qualified datetime in time-only input field? Really? :-) For now, I just changed the priorities of initial value initialization and pass two values to the datetimepicker html element.
P.S. I know the repo is depreciated in favor of the other fork, which is more outdated than this one, thank you for pointing that out. The issue is like 9 months old, so this is hardly relevant anyway.
eg:when i use Time Picking,set a default value ,such as
<input type="text" id="autoTime" class="datetimepicker form-control" data-date-format="hh:ii" data-link-format="hh:ii" value="01:01"/>
, it have a error