jquerytwitter-bootstrapdatepicker

Bootstrap Datepicker - Set default picker date, NOT display value


I'm using Bootstrap-Datepicker, and it's working really well.

One of the fields I'm using it for is a date of birth, and I know what the approximate age of the applicants is going to be, so it makes sense for me to default the picker to showing January 2000.

However, the only way I've found of doing this is to select a date, which actually updates the field with a value, which I don't want.

$(document).ready(function () {
    var datePickers = $('input[data-provide="datepicker"]');
    datePickers.each(function () {
        var datePicker = $(this);
        datePicker.datepicker('setDate', new Date(2000, 1, 1));
    });
});

Date of Birth

Is there a method in the object to select the view date or similar?

This is the default view I'm looking for:

Default Month

(Apologies if this is a duplicate - I looked but only found questions about how to actually pick dates.)


Solution

  • Here it is:

    $('.datepicker').datepicker({
        defaultViewDate: {year:2000, month:0, day:1},
    });
    

    And the js Fiddle:

    https://jsfiddle.net/mb34zwg3/