2

I need to disabled future weeks for jqueryUI calender, i tried something which is disabled future date. but i want future week disable and it's disabled the other dates of week 52 as well. please if anyone can help me in this. below is link of my work. in this you can see disabled dates of week 52. i want whole week selectable.

Fiddle Link of so far i done.

<input type="text" class="form-control weekcal-x" name="start" id="start" custom="" />

$(".weekcal-x").datepicker({
  showWeek: true,
  firstDay: 1,
  maxDate: new Date,
  onSelect: function(dateText, inst) {
    $(this).val("Week " + $.datepicker.iso8601Week(new Date(dateText)) + ', ' + $.datepicker.formatDate("yy", new Date(dateText)));

  }
}).datepicker('widget').addClass('ui-weekpicker');
$('.ui-weekpicker').on('mousemove', 'tr', function() {
  $(this).find('td a').addClass('ui-state-hover');
});
$('.ui-weekpicker').on('mouseleave', 'tr', function() {
  $(this).find('td a').removeClass('ui-state-hover');
});
JunaidFarooqui
  • 460
  • 5
  • 17

1 Answers1

0

Try this

maxDate: +7 instead of maxDate: new Date

Update

Get the first and last day of current week :

var currentDate = new Date; // get current date
var first = currentDate.getDate() - currentDate.getDay() + 1; // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6

var firstday = new Date(currentDate.setDate(first));
var lastday = new Date(currentDate.setDate(last));

Now you can use them as you want like maxDate: lastday, minDate:firstday

Ali Umair
  • 1,386
  • 1
  • 21
  • 42
  • [link] https://jsfiddle.net/junaidfarooqui/f2netnss/1/ the showing result is not accurate. it just let enable more 7 days not a week. i want to enable only current date's week. – JunaidFarooqui Dec 28 '15 at 12:55
  • I've updated my answer. for further info you can refer to this http://stackoverflow.com/questions/5210376/how-to-get-first-and-last-day-of-the-week-in-javascript – Ali Umair Dec 29 '15 at 05:52