sony angel
sony angel

Reputation: 1

Disable specific months in every year datetimepicker

I have a month year datetimepicker in this i want to disable all months in every year except jan ,june below code i tried but not working beforeshowmonth is not working

$('.newcqi').datetimepicker({

                viewMode: 'years',
                format: 'MM/YYYY',
                beforeShowMonth: function (date) {
                    var month = date.getMonth() + 1; // +1 because JS months start at 0
                   // var day = date.getDate();
                    return [!(month == 2 && month == 3 && month == 4 &&  month == 5 ), ""];
                }
                

            });

Upvotes: 0

Views: 770

Answers (2)

sony angel
sony angel

Reputation: 1

This below code worked for me for datetimepicker i am posting the code so that will help for others...

  $('.ddmmyyyyDate2newcqi').datetimepicker({


            viewMode: 'years',
            format: 'MM/YYYY',
            useCurrent: false
           });

    


      $(document).ready(function () {
            
    var event = document.getElementById("starttime_cqinew");
                event.addEventListener("mouseover", monthdisablestartime());

});
     function monthdisablestartime() {
                
                 var mS = ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                    for (var i = 0, length = mS.length; i < length; i++) {
    
                        $('.bootstrap-datetimepicker-widget table td > span:contains(' + mS[i] + ')').addClass('disabled').css("background-color", "lightgrey");
    
                    }
    
              
            }

Upvotes: 0

Faisal Janjua
Faisal Janjua

Reputation: 866

I'm assuming you are using jQuery UI library for date picker jQueryUI

Your question is little confusing for me but as I understand from code you want to Enable Jan, Feb, March, April May & June. and Disable Jul, Aug, Sep, Oct, Nov & Dec from every year.

So code will be like

$('input').datepicker({
    beforeShowDay: function(date){
        if(date.getMonth() === 0 || date.getMonth() === 1 || date.getMonth() === 2 || date.getMonth() === 3 || date.getMonth() === 4 || date.getMonth() === 5){
            return [true];
        }
        return [false]
    }
});

jsFiddle demo is here

Upvotes: 1

Related Questions