Bootstrap datepicker ocultar después de la selección
¿Cómo oculto el calendario después de seleccionar una fecha? ¿Hay alguna función específica que pueda usar? Mi código a continuación:
$('#dp1').datepicker({
format: 'mm-dd-yyyy',
startDate: '-15d',
autoclose: true,
endDate: '+0d' // there's no convenient "right now" notation yet
});
Cualquier ayuda sería apreciada.
16 answers
Puede usar event changedate()
para realizar un seguimiento de cuándo se cambia la fecha junto con datepicker('hide')
método para ocultar el datepicker
después de hacer la selección:
$('yourpickerid').on('changeDate', function(ev){
$(this).datepicker('hide');
});
ACTUALIZACIÓN
Este fue el error con autoclose: true
. Este error se solucionó en el último maestro. VER EL COMMIT. Obtener el último código de GitHub
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-05-28 04:58:05
Si ayuda a alguien, la versión 2.0 del datepicker de bootstrap ya no funciona con la respuesta aceptada.
Así es como lo conseguí trabajando en el mío:
$('yourpickerid').datepicker({
format: 'dd/mm/yyyy',
}).on('changeDate', function(e){
$(this).datepicker('hide');
});
Véase http://bootstrap-datepicker.readthedocs.org/en/latest/events.html#changedate
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-05-13 11:18:00
$('#input').datepicker({autoclose:true});
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-11-16 19:24:02
- , Simplemente abra el
bootstrap-datepicker.js
- buscar:
var defaults = $.fn.datepicker.defaults
- conjunto
autoclose: true
Guarde y actualice su proyecto y esto debería hacer.
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-11-14 16:13:59
Si está buscando anular el comportamiento del calendario en general, globalmente, intente editar la función Datepicker (en mi ejemplo, era la línea 82),
De
this.autoclose = false;
A
this.autoclose = true;
Funcionó bien para mí, ya que quería que todas las instancias de mi calendario se comportaran igual.
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-10-28 21:45:52
El problema se puede detener, bloqueando el evento hide para el elemento de entrada por esta línea:
var your_options = { ... };
$('.datetimepicker').datetimepicker(your_options).on('hide', function (e) {
e.preventDefault();
e.stopPropagation();
});
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-07-12 00:23:40
$('yourpickerid').datetimepicker({
pickTime: false
}).on('changeDate', function (e) {
$(this).datetimepicker('hide');
});
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-10-01 01:54:19
Cerrar datetimepicker cuando seleccione la fecha (datetimepicker mostrar fecha con hora)
$('.datepicker').datepicker({
autoclose: true,
closeOnDateSelect: true
});
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-02-15 12:55:33
Puede cambiar el código fuente, bootstrap-datepicker.js. Añade esto.hide (); como ne
if (this.viewMode !== 0) {
this.date = new Date(this.viewDate);
this.element.trigger({
type: 'changeDate',
date: this.date,
viewMode: DPGlobal.modes[this.viewMode].clsName
});
this.hide();//here
}
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-05-20 07:47:04
Tengo una solución perfecta:
$('#Date_of_Birth').datepicker().on('changeDate', function (e) {
if(e.viewMode === 'days')
$(this).blur();
});
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-06-09 18:57:29
$('.datepicker').datepicker({
autoclose: true
});
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-01-15 20:53:07
Tener problemas con el reloj todavía mostrando incluso si yo escribí formato: 'AAAA-MM-DD', tuve que establecer pickTime: false y después del cambio - > ocultar Tuve que enfocar - > mostrar
$('#VBS_RequiredDeliveryDate').datetimepicker({
format: 'YYYY-MM-DD',
pickTime: false
});
$('#VBS_RequiredDeliveryDate').on('change', function(){
$('.datepicker').hide();
});
$('#VBS_RequiredDeliveryDate').on('focus', function(){
$('.datepicker').show();
});
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-04-12 07:51:10
Para el selector de fecha y hora
$('yourpickerid').datetimepicker({
format: 'dd/mm/yyyy',
}).on('changeDate', function(e){
$(this).datetimepicker('hide');
});
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-02-18 07:17:31
Cambié a datetimepicker y el formato a 'DD / MM/AAAA'
$("id").datetimepicker({
format: 'DD/MM/YYYY',
}).on('changeDate', function() {
$('.datepicker').hide();
});
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-07-12 05:03:47
Al menos en la versión 2.2.3 que estoy usando, debes usar autoClose
en lugar de autoclose
. El caso de las cartas importa.
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-09-01 16:45:00
Use esto para datetimepicker, funciona bien
$('#Date').datos ("DateTimePicker").hide ();
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-11-24 09:37:59