Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Datepicker unable to set start/end dates

Here is code:

<input type="text" class="datepicker" id="flight_start" placeholder="mm-dd-yyyy" data-date-format="mm-dd-yyyy">

...

<script src="/ui/js/jquery.js"></script>
<script src="/ui/js/bootstrap.js"></script>
<script src="/ui/js/datatables/jquery.dataTables.min.js"></script>
<script src="/ui/js/datatables/DT_bootstrap.js"></script>
<script src="/ui/js/responsive-tables/responsive-tables.js"></script>
<script src="/ui/js/datepicker/date.js"></script>
<script src="/ui/js/datepicker/daterangepicker.js"></script>
<script src="/ui/js/chosen/chosen.jquery.js"></script>
<script src="/ui/js/bootstrap-wizard/bootstrap-wizard.js"></script>
<script src="/ui/js/sparkline/jquery.sparkline.min.js"></script>
<script src="/ui/js/datepicker/bootstrap-datepicker.js"</script>

...

<script type="text/javascript">
    $('#flight_start').datepicker({
        format: "mm-dd-yyyy",
        startDate: "+1d"
    });
</script>

The format works, but not the start date. I get no errors/warnings, simply does not work. Dates prior to the start date are not grayed out in any way and can be selected. I want to remove this ability. Thanks!

Edit: I've also tried

$('#flight_start').datepicker('setStartDate', '+1d');

Which gives me

Uncaught TypeError: Object [object Object] has no method 'setStartDate'
like image 989
Wes Avatar asked Mar 23 '23 02:03

Wes


2 Answers

Looks like the problem was I had an out of date version of bootstrap-datepicker.js.

A coworker just picked up the plugin so I'm not sure why he downloaded an out of date version, oh well.

like image 146
Wes Avatar answered Apr 10 '23 05:04

Wes


Try this code, worked for me. disabled dates prior to today

$("YOURSELECTOR").datepicker({
     format: 'dd/mm/yyyy',
     startDate:new Date()
});

Remember this is bootstrap picker

like image 29
Usman Younas Avatar answered Apr 10 '23 06:04

Usman Younas