Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 228
Octopoid Avatar asked Jun 05 '15 20:06

Octopoid


People also ask

How do I change the default date format in bootstrap datepicker?

Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.

How do I change the default date in datepicker?

Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );

How do I stop datepicker pop up?

datepicker(). on('changeDate', function (ev) { $('#example1'). Close(); });


1 Answers

Here it is:

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

And the js Fiddle:

https://jsfiddle.net/mb34zwg3/

like image 101
Tim Lewis Avatar answered Sep 30 '22 01:09

Tim Lewis