问题
I am using bootstrap date-time picker in my Java Spring MVC web application to select date and time separately. I have included the CSS and scripts required. my HTML code would be as follows:
<div class="form-group">
<label class="col-lg-2 control-label">Start</label>
<div class="col-lg-10">
<div class="row">
<div class="col-sm-6">
<!--Bootstrap Datepicker : Component-->
<div id="dripCampaignStartDate">
<label class="control-label" for="startDate">Start Date</label>
<div class="input-group date">
<input type="text" class="form-control" id="startDate" name="startDate" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-calendar-4"></i></span>
</div>
</div>
</div>
<div class="col-sm-6">
<!--Bootstrap Timepicker : Component-->
<label class="control-label" for="startTime">Start Time</label>
<div class="input-group date" id="dripCampaignStartTime">
<input type="text" class="form-control" id="startTime" name="startTime" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-clock"></i></span>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">End</label>
<div class="col-lg-10">
<div class="row">
<div class="col-sm-6">
<!--Bootstrap Datepicker : Component-->
<div id="dripCampaignEndDate">
<label class="control-label" for="endDate">End Date</label>
<div class="input-group date">
<input type="text" class="form-control" id="endDate" name="endDate" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-calendar-4"></i></span>
</div>
</div>
</div>
<div class="col-sm-6">
<!--Bootstrap Timepicker : Component-->
<label class="control-label" for="endTime">End Time</label>
<div class="input-group date" id="dripCampaignEndTime">
<input type="text" class="form-control" id="endTime" name="endTime" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-clock"></i></span>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">DNS Time</label>
<div class="col-lg-10">
<div class="row">
<div class="col-sm-6">
<!--Bootstrap Datepicker : Component-->
<label class="control-label" for="DNSStartTime">From</label>
<div class="input-group date" id="dripCampaignDNSStartTime">
<input type="text" class="form-control" id="DNSStartTime" name="DNSStartTime" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-clock"></i></span>
</div>
</div>
<div class="col-sm-6">
<!--Bootstrap Datepicker : Component-->
<label class="control-label" for="DNSEndTime">To</label>
<div class="input-group date" id="dripCampaignDNSEndTime">
<input type="text" class="form-control" id="DNSEndTime" name="DNSEndTime" readonly="readonly">
<span class="input-group-addon"><i class="swcm-pli-clock"></i></span>
</div>
</div>
</div>
</div>
</div>
I am using the following javascript code to initialize the date and time pickers: //Initializing date time pickers
var currentDate = new Date();
var tomorrow = new Date();
tomorrow.setDate(currentDate.getDate() + 1);
var minDateValue = new Date();
var maxDateValue = new Date();
$('#dripCampaignStartDate .date').datetimepicker({
format: 'L',
allowInputToggle: true,
ignoreReadonly: true,
useCurrent: false,
minDate: currentDate,
defaultDate: currentDate
});
$('#dripCampaignEndDate .date').datetimepicker({
format: 'L',
allowInputToggle: true,
ignoreReadonly: true,
useCurrent: false,
minDate: currentDate,
defaultDate: currentDate
});
$('#dripCampaignEndDate .date').data("DateTimePicker").date(tomorrow);
$("#dripCampaignStartDate .date").on("dp.change", function (e) {
$('#dripCampaignStartDate .date').data("DateTimePicker").minDate(moment().millisecond(0).second(0).minute(0).hour(0));
minDateValue = new Date(e.date);
minDateValue.setDate(minDateValue.getDate());
minDateValue.setHours(0,0,0,0);
$('#dripCampaignEndDate .date').data("DateTimePicker").minDate(minDateValue);
if($('#dripCampaignEndDate .date').data("DateTimePicker").date() < $('#dripCampaignStartDate .date').data("DateTimePicker").date())
{
tomorrow = new Date(minDateValue);
tomorrow.setDate(tomorrow.getDate() + 1);
$('#dripCampaignEndDate .date').data("DateTimePicker").date(tomorrow);
}
});
$("#dripCampaignEndDate .date").on("dp.change", function (e) {
minDateValue.setHours(0,0,0,0);
$('#dripCampaignEndDate .date').data("DateTimePicker").minDate(minDateValue);
maxDateValue = new Date(e.date);
maxDateValue.setDate(maxDateValue.getDate());
$('#dripCampaignStartDate .date').data("DateTimePicker").minDate(moment().millisecond(0).second(0).minute(0).hour(0));
maxDateValue.setHours(0,0,0,0);
$('#dripCampaignStartDate .date').data("DateTimePicker").maxDate(maxDateValue);
});
currentDate.setTime(currentDate.getTime() + (60*60*1000));
$('#dripCampaignStartTime, #dripCampaignEndTime, #dripCampaignDNSStartTime, #dripCampaignDNSEndTime').timepicker({
defaultTime: currentDate
});
$('#start-Time').val($('#dripCampaignStartTime').val());
$('#endTime').val($('#dripCampaignEndTime').val());
$('#DNSStartTime').val($('#dripCampaignDNSStartTime').val());
$('#DNSEndTime').val($('#dripCampaignDNSEndTime').val());
$(document).on( 'change', '#dripCampaignStartTime' ,function (event){
$('#start-Time').val($('#dripCampaignStartTime').val());
});
$(document).on( 'change', '#dripCampaignEndTime' ,function (event){
$('#endTime').val($('#dripCampaignEndTime').val());
});
$(document).on( 'change', '#dripCampaignDNSStartTime' ,function (event){
$('#DNSStartTime').val($('#dripCampaignDNSStartTime').val());
});
$(document).on( 'change', '#dripCampaignDNSEndTime' ,function (event){
$('#DNSEndTime').val($('#dripCampaignDNSEndTime').val());
});
I have no issue with selecting date. The issue happens with the time picker. I found few solutions related to z index, but dint seem to work for me.
回答1:
After some research, I found the solution from the following URL:
https://github.com/jdewit/bootstrap-timepicker/issues/326
I added a CSS entry to my stylesheet to set the z-index for the time picker and the issue was solved:
.bootstrap-timepicker-widget.dropdown-menu { z-index: 1050!important; }
来源:https://stackoverflow.com/questions/51654736/time-picker-going-behind-the-twitter-bootstrap-modal