0

I use date picker with only option with months but i need to display some months for this date picker like (May ,Nov)

I use Following code:

$('.month-year').datepicker({ format: "mm-yyyy", viewMode: "months", minViewMode: "months" }) 

Current Output
enter image description here

*From Above Display only months (May ,Nov).

2
  • So, you want to disable Feb to Nov months? Commented Oct 19, 2016 at 5:54
  • Display Months only May And Nov. Commented Oct 19, 2016 at 5:58

3 Answers 3

1

I wasn't sure if you want to just make the other months inactive or to hide them completely from the date picker, so I've included both options. The demo currently hides them completely.

var monthsToShow = ['May', 'Nov']; $('#example1').datepicker({ format: "MM yyyy", minViewMode: 1, autoclose: true }).on("show", function(event) { $(".month").each(function(index, element) { var el = $(element); // to make other months inactive use this: if ($.inArray(el.text(), monthsToShow) >= 0) el.removeClass('disabled'); else el.addClass('disabled'); // to hide inactive months use this: if ($.inArray(el.text(), monthsToShow) >= 0) el.show(); else el.hide(); }); }); 

Here's the fiddle: http://jsfiddle.net/awv3cx4x/

Sign up to request clarification or add additional context in comments.

1 Comment

This solution does not account for years, isn't it? Meaning, cannot set different months disabled per selected year.
0

you can use beforeShowDay event listener

$( "#datepicker" ).datepicker({ beforeShowDay: disableSpecificWeekDays }); var monthsToDisable = [1, 2, 3]; function disableSpecificWeekDays(date) { var month = date.getMonth(); if ($.inArray(month, monthsToDisable) != -1) { return [false]; } return [true]; } 

DEMO

2 Comments

OP is looking for Bootstrap Datepicker and not jQuery Datepicker
@Newbee Dev: Code Not Working. i Use Bootstrap Datepicker
0

try this answer from @J Santosh

https://stackoverflow.com/a/32103637/6952155

this is the fiddle

http://jsfiddle.net/santoshj/z2v31Leo/3/

snippet

$(document).ready(function() { var dateStart = new Date(); dateStart.setDate(dateStart.getDate()-1); var dp = document.getElementById("datepicker1"); $("#datepicker1").datepicker( { format: "mm-yyyy", startView: "months", minViewMode: "months", startDate: dateStart, datesDisabled: dp.dataset.datesDisabled.split() }).datepicker("setDate",null); $("#datepicker1").on('changeMonth',function(date){ console.log(date.date.getMonth()+1); }) });
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script> <div class="modal-body"> <div class="input-append date" id="datepicker1" data-date="Aug-2015" data-date-format="mm-yyyy" data-dates-disabled="Sep-2015,Oct-2015" style="display:inline-block; font-weight:bold;"> Check In: <input type="text" readonly="readonly" name="date1" > <span class="add-on"><i class="glyphicon glyphicon-calendar"></i></span> </div> </div> 

2 Comments

I Need To Display Only May and Nov Months.
you can edit that code. i already give you the working code that disables the months why not play with it? your expecting for an answer that give you the exact output you want? effort man.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.