Bootstrap datepicker disabling past dates without current date

前端 未结 20 2177
[愿得一人]
[愿得一人] 2020-11-27 04:55

I wanted to disable all past date before current date, not with current date. I am trying by bootstrap datepicker library \"bootstrap-datepicker\" and using following code:<

20条回答
  •  春和景丽
    2020-11-27 05:28

    If your requirement is to disable the startDate and endDate dynamically based on one on another you can you this.

    $('#date2').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true
            }).on('show', function(e){
                var date = $('#date3').datepicker('getDate');
                if(date){
                 $('#date2').datepicker('setEndDate', date);
                    }
        });
    
            $('#date3').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true
            }).on('show', function(e){
                var date = $('#date2').datepicker('getDate');
                if(date){
                 $('#date3').datepicker('setStartDate', date);
                    }
        });
    

    If your requirement is just disabled past dates then you can use below snippet.

    $('#date2').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true,
                startDate : new Date()
            })
    

    If your requirement is just disabled future dates then you can use below snippet.

     $('#date2').datepicker({
                    todayHighlight: true,
                    autoclose: true,
                    format: "dd/mm/yyyy",
                    clearBtn : true,
                    endDate : new Date()
                })
    

    I hope it will help someone.

提交回复
热议问题