I am currently using the Twitter Bootstrap framework, and when using the modal windows I cannot get over js elements to work like datepicker or validation, though chosen and
$('#effective_to').datepicker({
dateFormat: "dd-mm-yyyy",
changeMonth: true,
changeYear: true,
beforeShow: function() {
$('#ui-datepicker-div').addClass('datepicker');
}
});
CSS
.datepicker {
z-index: 100000 !important;
display: block;
}
This works form me. Even though I called model via ajax
Wrap your datapicker JavaScript code inside
function pageLoad() {}
I use:
body.modal-open .datepicker {
z-index: 1200 !important;
}
This way: if the modal isn't open, and you want the datepicker to be at the normal z-index (in my case I needed it to be under the menu drop-down, which has a z-index of 1000), it works.
If the modal is open, the datepicker needs to be over the modal z-index (1040 or 1050), so use the body.modal-open
selector.
I'm using Bootstrap 3.1.1
This solutions worked perfectly for me to render the datepicker on top of bootstrap modal.
http://jsfiddle.net/cmpgtuwy/654/
HTML
<br/>
<div class="wrapper">
Some content goes here<br />
Some more content.
<div class="row">
<div class="col-xs-4">
<!-- padding for jsfiddle -->
<div class="input-group date" id="dtp">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon"></span>
</span>
</div>
</div>
</div>
</div>
Javascript
$('#dtp').datetimepicker({
format: 'MMM D, YYYY',
widgetParent: 'body'});
$('#dtp').on('dp.show', function() {
var datepicker = $('body').find('.bootstrap-datetimepicker-widget:last');
if (datepicker.hasClass('bottom')) {
var top = $(this).offset().top + $(this).outerHeight();
var left = $(this).offset().left;
datepicker.css({
'top': top + 'px',
'bottom': 'auto',
'left': left + 'px'
});
}
else if (datepicker.hasClass('top')) {
var top = $(this).offset().top - datepicker.outerHeight();
var left = $(this).offset().left;
datepicker.css({
'top': top + 'px',
'bottom': 'auto',
'left': left + 'px'
});
}
});
CSS
.wrapper {
height: 100px;
overflow: auto;}
body {
position: relative;
}
According to http://www.daterangepicker.com/ (options)
$('#dispatch_modal').on('shown.bs.modal', function() {
$('input:text:visible:first').focus();
// prepare datepicker
$('.form_datepicker').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
parentEl: '#dispatch_modal'
});
});
`
parentEl solved my problem...
for me it only worked with !important in css
.datepicker {z-index: 1151 !important;}