For information as to versions, using Bootstrap 3.0.0 (built in with the new MVC templates if I remember correctly), Bootstrap-datetimejs 4.0.0 (https://github.com/Eonasdan/bootstrap-datetimepicker), and ASP.NET MVC 5.
Using MVC, I'm rendering out a bunch of fields, but this one has existing data (this is when inspecting element in Chrome so it isn't HTMLHelper code):
<input class="form-control timepicker input-validation-error" data-format="hh:mm PP"
data-val="true" data-val-date="The field Start (Time) must be a date."
data-val-required="The Start (Time) field is required."
id="MaintenanceSundayTimeStart"
name="MaintenanceSundayTimeStart" type="text" value="1/1/2000 8:00:00 PM">
The code that generates it:
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.MaintenanceSundayTimeStart)
@Html.TextBoxFor(model => model.MaintenanceSundayTimeStart,
new { @data_format = "hh:mm PP", @class = "form-control timepicker" })
</div>
</div>
When page loads, I call this:
$('.timepicker').each(function () {
$(this).datetimepicker({
format: 'LT'
});
});
edit: have attempted to try this:
$('.timepicker').each(function () {
$(this).datetimepicker({
pickDate: false
});
});
and set the data-format to this based on looking at the moment.js documentation, though the slashes and the colons aren't included by I assume they can be dropped in (to match the 1/1/2000 8:00:00 PM)
data-format="M/D/YYYY H:mm:ss A"
And it still seems to be unable to parse the datetime.
For some reason, when the control renders, in the textbox I'm seeing a totally different time listed (1:00 PM) which tells me that it may just be unable to parse out that value. I do want the render to be hour:minute AM/PM only, but I think I have to bind to a standard DateTime object, right? Looking at the source, it looks like input-validation-error is injected so that may be my larger issue of submitting the form just focusing the text box.
Is there something I'm doing incorrectly? I know I want to take in a "mm/dd/YYYY hh:mm:ss PP" and have it parse out as just the "hh:mm PP" part parse out. When saving, I really only care about the time component (I force the date to 1/1/2000 regardless as I am not concerned with the date component at all).
edit: after more attempts, I've noticed that the value being parsed (primarily by dumping in other values) is that the value seems to pull the MM part as the hour. The input is going to be a full datetime, but I only want the user to be given the time component to manage (I force all dates to just 1/1/2000). At this stage, I think if I can get that part done, I'll be good.