admin管理员组文章数量:1322850
I need to use bootstrap datetimepicker in a bootstrap modal. I've successfully used it in a normal web page. The bootstrap calender won't open in the modal. Here is my dynamically generated html
code.
'<div class="col-xs-12">'+
'<div class="col-xs-4">'+
'<div class="form-group">'+
'<label for="editStartTime">Start Time </label>'+
'<div class="input-group date" id="editStartTime">'+
'<input type="text" class="form-control" value="'+startTime+'"/>'+
'<span class="input-group-addon">'+
'<span class="glyphicon glyphicon-calendar"></span>'+
'</span>'+
'</div>'+
'</div>'+
'</div>'
This is the jquery
part.
$(function () {
$('#editStartTime').datetimepicker();
});
what will be the issue?
I need to use bootstrap datetimepicker in a bootstrap modal. I've successfully used it in a normal web page. The bootstrap calender won't open in the modal. Here is my dynamically generated html
code.
'<div class="col-xs-12">'+
'<div class="col-xs-4">'+
'<div class="form-group">'+
'<label for="editStartTime">Start Time </label>'+
'<div class="input-group date" id="editStartTime">'+
'<input type="text" class="form-control" value="'+startTime+'"/>'+
'<span class="input-group-addon">'+
'<span class="glyphicon glyphicon-calendar"></span>'+
'</span>'+
'</div>'+
'</div>'+
'</div>'
This is the jquery
part.
$(function () {
$('#editStartTime').datetimepicker();
});
what will be the issue?
Share Improve this question edited Jul 20, 2015 at 16:21 Shashika asked Jul 20, 2015 at 15:21 ShashikaShashika 1,6368 gold badges28 silver badges49 bronze badges6 Answers
Reset to default 7You need to instantiate the datepicker again after the dynamic html is added to the DOM. You could call it on the bootstrap modal shown event:
$('.modal').on('shown.bs.modal', function () {
$('#editStartTime').datetimepicker();
});
add z-index above 1051 in class datepicker
add something like this in page or css
<style>
.datepicker{z-index:1151 !important;}
</style>
'StartTime' isn't found as as ID in your sample.
Perhaps you need to use '#editStartTme'
I don't think you're targeting the correct element. You specify $("#StartTime")...
which would look for an element in your HTML with an ID (#) of id="StartTime"
. Notice in your provided HTML that doesn't exist:
<input type="text" class="form-control" value="'+startTime+'"/>'+
Either add an id id="startTime"
or class class="form-control startTime
and target it properly in your jQuery:
$(function () {
$('#startTime').datetimepicker(); // # for ID
// or
$('.startTime').datetimepicker(); // . for class
});
Listen to the event show.bs.modal
which occurs when the modal is about to be shown, so you can get the input instance when it's already created in the document to configure the datetimepicker
.
$(document).on('show.bs.modal','.modal', function () {
$('#editStartTime').datetimepicker();
})
Keeps this js before end of script. This works for me.
// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
$confModal.on('hidden', function() {
$.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});
本文标签: javascriptbootstrap datetimepicker does not work in a bootstrap modalStack Overflow
版权声明:本文标题:javascript - bootstrap datetimepicker does not work in a bootstrap modal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742113206a2421349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论