I am using the Tempus Dominus Timepicker v5.0.1 with jquery 3.4.1 and the latest version of moment.js. I have a form that has a registration start date and time and a registation end date and time. I want the user to be able to select the date and after they click a date I want the time to appear automatically (the equivalent of clicking the clock button at the bottom).
I have my view:
<div class="form-row">
<div class="col-md-4 col-lg-3 mb-3">
@Html.LabelFor(m => m.RegistrationStartDate, new { @class = "font-weight-bold label-required" })
@Html.TextBoxFor(m => m.RegistrationStartDate, new { @class = "form-control datetimepicker-input", placeholder = RecruitClassResource.RegistrationStartDate, required = "required", id="datetimepicker1", data_toggle="datetimepicker", data_target="#datetimepicker1" })
@Html.ValidationMessageFor(m => m.RegistrationStartDate)
</div>
</div>
<div class="form-row">
<div class="col-md-4 col-lg-3 mb-3">
@Html.LabelFor(m => m.RegistrationEndDate, new { @class = "font-weight-bold label-required" })
@Html.TextBoxFor(m => m.RegistrationEndDate, new { @class = "form-control datetimepicker-input", placeholder = RecruitClassResource.RegistrationEndDate, required = "required", id="datetimepicker2", data_toggle="datetimepicker", data_target="#datetimepicker2" })
@Html.ValidationMessageFor(m => m.RegistrationEndDate)
</div>
</div>
javascript:
@section Scripts {
@Scripts.Render("~/Scripts/moment.min.js")
@Scripts.Render("~/Scripts/tempusdominus-bootstrap-4.js")
<script>
$(document).ready(function () {
$('.datetimepicker-input').datetimepicker({
icons: {
time: "far fa-clock"
}
});
$('.datetimepicker-input').on('change.datetimepicker', function (e) {
// Just a test to see when this event is fired
alert(e.date);
});
});
</script>
}
I thought maybe the change.datetimepicker would be the event listener I was looking for, but it is fired the first time I click the textbox because the value changes from null to the current date. I also am not sure what I would need to call for the time to appear when a date is selected.