bootstrap datetimepicker does not work in a bootstrap modal

↘锁芯ラ 提交于 2019-12-07 01:54:26
ijsnow

You 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
});
Germano Plebani

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();
})
Amit Adav

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;
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!