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.

Author: 93196.93, 2014-01-16

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');
});

Demo

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

 132
Author: Felix,
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

 39
Author: Ola,
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});
 23
Author: Salim,
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
  1. , Simplemente abra el bootstrap-datepicker.js
  2. buscar: var defaults = $.fn.datepicker.defaults
  3. conjunto autoclose: true

Guarde y actualice su proyecto y esto debería hacer.

 3
Author: user3615318,
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.

 2
Author: user3674664,
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();
});
 2
Author: papacho,
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');

  });
 1
Author: mirmo,
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
}); 
 1
Author: Gosha,
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

}

 0
Author: Vladimir Kulakov,
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();
});
 0
Author: Gordon Ma,
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
}); 
 0
Author: user3706926,
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();
});
 0
Author: dyrwoolf,
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');
    });
 0
Author: srinivas gowda,
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();
});
 0
Author: Sorter,
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.

 0
Author: TimA,
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 ();

 0
Author: sugumar,
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