简体   繁体   中英

How to disable future months from current months in bootstrap datepicker

In am using a calendar in bootsrtap datepicker, in that I have displaying only month and year (mm-yyy). I want to disable future months from current month. I have searched a lot but I didn't find an answer. Please help me, I have attached my code below

JS :

$(document).ready(function () {

        var cou = $('#rolecount').val();
        var c;

        for (c = 0; c <=cou; c++){
            $('#datepicker'+c).datepicker({
            format: 'mm-yyyy',
            endDate: '+0d',
            viewMode: "months", 
            minViewMode: "months",
            });  

        $('#datepicker'+c).datepicker().on('monthSelected', function(ev){
            $(this).datepicker('hide');
        });
        }
    });

HTML:

<div class="input-group date">
    <input type="text" id="datepicker<?=$j?>" required name="joindate<?=$j?>" class="date_picker form-control" placeholder="show datepicker" maxlength="100"  autocomplete="off"><span class="input-group-addon" id="basic-addon2"><i class="fa fa-calendar"></i></span>
    <input type="hidden" name="roleid<?=$j?>" value="<?=$str[$j]?>"  />
</div>

You need to redefine your endDate option value:

$('.input-daterange').datepicker({
   format: 'mm-yyyy',
   // You used '+0d' that is for days instead of '+0m' that is for months.
   endDate: '+0m',
   viewMode: "months", 
   minViewMode: "months"
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM