Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Datepicker - Set startView: 'decade', but not current decade

Currently I have the startView showing the current decade, which is ok but I want to make the previous decade be the startView - not the current decade.

this.dobDatePickerView = new DatePickerView({
  el: this.$('[name="dob"]'),
  startView : 'decade',
  endDate   : this.sandbox.dates().fwFormat('date'),
  value     : this.sandbox.dates().subtract('years', 18).fwFormat('date')
}).render();

I want to subtract 18 years from the decade view default selected year, so instead of '2013' being pre-selected it should default to 1995.

like image 927
jamiescript Avatar asked Mar 19 '13 15:03

jamiescript


1 Answers

This could work: (demo):

<div class="input-append date" id="dp1" data-date="01-01-1990" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
    <input class="span2" size="16" type="text" readonly>
    <span class="add-on"><i class="icon-calendar"></i></span>
</div>
<script>
  $('#dp1').datepicker();
</script>

By separating the datepicker from the input and setting a default value on the picker but not the input, you can get something that will only populate a date once a date is selected but start at any value you please.

like image 136
Jason Sperske Avatar answered Oct 23 '22 13:10

Jason Sperske