Implementación de jQuery DatePicker en el modo Bootstrap
Creado jsfiddle para mi problema http://jsfiddle.net/sudiptabanerjee/93eTU/
En la ventana modal el problema está en los combos de Cambio de Mes y Cambio de Año.
A) IE 11: todo está funcionando como se esperaba b) Chrome Versión 31, En mes combo select, bootstrap modal hides. c) Firefox v26, Mes y Año desplegable no es funcional.
Por favor ayuda.
HTML
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="row">
<label for="idTourDateDetails">Tour Start Date:</label>
<div class="form-group">
<div class="input-group">
<input type="text" name="idTourDateDetails" id="idTourDateDetails" readonly="readonly" class="form-control clsDatePicker"> <span class="input-group-addon"><i id="calIconTourDateDetails" class="glyphicon glyphicon-th"></i></span>
</div>
</div>Alt Field:
<input type="text" name="idTourDateDetailsHidden" id="idTourDateDetailsHidden">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
CSS
.clsDatePicker {
z-index: 100000;
}
JS
$('#idTourDateDetails').datepicker({
dateFormat: 'dd-mm-yy',
minDate: '+5d',
changeMonth: true,
changeYear: true,
altField: "#idTourDateDetailsHidden",
altFormat: "yy-mm-dd"
});
4 answers
Esto se debe a que el modal impone centrarse en sí mismo. Aquí hay una solución para esto como se menciona aquí . Agregue el siguiente script a su archivo js. Eso es.
JQuery
// 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;
});
$confModal.modal({ backdrop : false });
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:17:09
jQuery
version of @crftr answer
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
try{
$confModal.on('hidden', function() {
$.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});
$confModal.modal({ backdrop : false });
}
catch (error) {
if(error.name != 'ReferenceError')
throw error;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-21 09:11:37
MÁS FÁCIL... solo tienes que comentar esta línea en tu boostrap.js eso.enforceFocus().
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-25 15:42:50
Basándome en la respuesta de Surjith, agregué un bloque try/catch para resolver una excepción ReferenceError para confModal
siendo indefinida.
Coffeescript:
enforceModalFocusFn = $.fn.modal.Constructor::enforceFocus
$.fn.modal.Constructor::enforceFocus = ->
try
$confModal.on "hidden", ->
$.fn.modal.Constructor::enforceFocus = enforceModalFocusFn
return
$confModal.modal backdrop: false
catch error
if error.name != 'ReferenceError'
throw error
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-03 20:07:48