Bootstrap datepicker hide after selection

前端 未结 18 2617
暖寄归人
暖寄归人 2020-12-13 01:30

How do I hide the calendar after a date is selected? Is there a specific function that I can use? My code below:

$(\'#dp1\').datepicker({
    format: \'mm-d         


        
相关标签:
18条回答
  • 2020-12-13 01:58
    $('.datepicker').datepicker({
        autoclose: true
    }); 
    
    0 讨论(0)
  • 2020-12-13 02:03
    1. Simply open the bootstrap-datepicker.js
    2. find : var defaults = $.fn.datepicker.defaults
    3. set autoclose: true

    Save and refresh your project and this should do.

    0 讨论(0)
  • 2020-12-13 02:04

    You can change source code, bootstrap-datepicker.js. Add this.hide(); like 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 讨论(0)
  • 2020-12-13 02:07

    You can use event changedate() to keep track of when the date is changed together with datepicker('hide') method to hide the datepicker after making selection:

    $('yourpickerid').on('changeDate', function(ev){
        $(this).datepicker('hide');
    });
    

    Demo

    UPDATE

    This was the bug with autoclose: true. This bug was fixed in latest master. SEE THE COMMIT. Get the latest code from GitHub

    0 讨论(0)
  • 2020-12-13 02:07
    $('yourpickerid').datetimepicker({
               pickTime: false
    }).on('changeDate', function (e) {
               $(this).datetimepicker('hide');
    });
    
    0 讨论(0)
  • 2020-12-13 02:07

    At least in version 2.2.3 that I'm using, you must use autoClose instead of autoclose. Letter case matters.

    0 讨论(0)
提交回复
热议问题