Search code examples
bootstrap-datepicker

Bootstrap datepicker autoset alone


I need some help with bootstrap datepicker, I do not why, but when user press some key in keyboard, datepicker automatic fill the last day in month.


Solution

  • That's a default option from the datepicker to parse any input (alphabetic characters, wrong date formatting, etc) to the closest date to that input. So a letter will parse to the current date.

    You can disable this behavior with the forceParse option

    $(document).ready(function(){
        $('#datepicker').datepicker({
            format: 'dd/mm/yyyy', 
            autoclose: true, 
            todayHighlight: true,
            forceParse: false,
        });
    });
    

    Example: http://jsfiddle.net/zcvq0yhh/20/