0

I want to disable all dates excepting from range of start_date and end_date for eg : date start from 26/05/2015 to 29/05/2015 so all the dates before start and after end get disable. For this I am using pickadate and pickadate month indexing start from zero.

$('.datepicker2').pickadate({
        format: 'dd/md/yyyy',
        selectMonths: true,
        selectYears: 25,
min: [$("#leave_start_date").val().split("/").map(Number).reverse()],
max: [$("#leave_end_date").val().split("/").map(Number).reverse()]
});

but it is not working. It disable all dates remaining current date. Please guide me how to solve this. I want to disable that dates only who is not coming in range of start_date and end_date values.

Dinshaw Raje
  • 933
  • 1
  • 12
  • 33
Aniee
  • 81
  • 12

1 Answers1

2

I think the first issue is that the values for min and max can take an array like [2014,05,26] but with that map, I suspect you're sending an array nested in an array [[2014,05,26]]

'15/05/2015'.split('/').map(Number)
JS> [15, 5, 2015]
'15/05/2015'.split('/').map(Number).reverse()
JS> [2015, 5, 15]  <<<<< this is what (i think) pickadate wants
['15/05/2015'.split('/').map(Number).reverse()]
JS> [Array[3]]    <<<<< this is what (i think) you are sending

Also, as you mentioned in the title, the month counter that pickadate expects starts at 0. With a little helper function like this

function formatDateForPickadate(date_string) {
  vals = date_string.split('/').map(Number).reverse()
  vals[1] -= 1
  return vals
}

you can do:

min: formatDateForPickadate($("#leave_start_date").val()),
max: formatDateForPickadate($("#leave_end_date").val())

And the offset month will get fixed properly.

mr rogers
  • 3,200
  • 1
  • 19
  • 31
  • When I made the first cut, I didn't realize the month offset was also part of the issue. Glad this worked out. – mr rogers May 26 '15 at 06:58