Dolove Igo
Dolove Igo

Reputation: 7

How to make a date other than the date of today's disabled by bootstrap datepicker

How do I prevent other dates are disabled, except the date of this day I use bootstrap datepicker, please solution.

<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#tanggal').datepicker({
            format: "yyyy-mm-dd",
            autoclose:true,
        });
    });
</script>
<div class="form-group">
    <div class="input-group">
        <div class="input-group-addon">
            <span class="fa fa-calendar"></span> 
        </div> <!-- end class input-group-addon -->
        <input type="text" id ="tanggal" name="date" class="form-control" placeholder="Pilih Tanggal" style="width:20%;" required>
    </div>
</div>

Upvotes: 0

Views: 60

Answers (1)

pulekies
pulekies

Reputation: 924

The following code will disable all dates other than today.

$('#tanggal').datepicker({
    format: "yyyy-mm-dd",
    autoclose:true,
    startDate: "today",
    endDate: "today",
});

Please see the following documentation for more info:

https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#startdate

Here is a JSFiddle that I was using to investigate. http://jsfiddle.net/MgcDU/12661/

Upvotes: 1

Related Questions