Bootstrap datepicker not close automatically after picking a date

前端 未结 12 1598
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 12:41

I use the latest Bootstrap datepicker.js. All works fine except that when I pick a date from the drop down, it does not automatically close it. I searched web and tried to u

相关标签:
12条回答
  • 2020-12-24 13:16

    I added autoclose: true, (with semi comma at the end and it works)

     $('.datepicker').datepicker({
        format: 'dd/mm/yyyy',
        todayHighlight:'TRUE',
        autoclose: true,
    })
    
    0 讨论(0)
  • 2020-12-24 13:16

    Try this. It's work for me.

    <input data-auto-close="true" type="text" class="datepicker-here"/>
    
    0 讨论(0)
  • 2020-12-24 13:19

    None of the above worked for me, however overriding the datepicker default option worked like a charm, and is a one-liner:

    $.fn.datepicker.defaults.autoclose = true;
    
    0 讨论(0)
  • 2020-12-24 13:27

    Try this:

    $('#selectDate').datepicker()
    .on('changeDate', function(ev){                 
        $('#selectDate').datepicker('hide');
    });
    

    Update:

    autoclose works fine when you use the updated version of datepicker present on github:

    https://github.com/eternicode/bootstrap-datepicker

    0 讨论(0)
  • 2020-12-24 13:27

    If you have multiple textboxes for which you have applied datepicker, then old solution might cause problem, Please try this instead,

    $('.datepicker').datepicker({
         format: "dd/mm/yyyy",
         autoclose: true,
    }).on('changeDate', function (ev) {
         $(this).datepicker('hide');
    });
    

    Look out this, https://github.com/eternicode/bootstrap-datepicker/issues/500

    Note: Do not forget, we are using class selector of jquery, so you need to apply datepicker class to your textbox.

    0 讨论(0)
  • 2020-12-24 13:27

    This worked for me

    $(".date-picker").change(function() { 
        setTimeout(function() {
            $(".date-picker").datepicker('hide'); 
            $(".date-picker").blur();
        }, 50);
    });    
    
    0 讨论(0)
提交回复
热议问题