1

I am using this date range picke (http://www.daterangepicker.com/#options)

Here are some of options, I understand the most but I need help about "isInvalidDate"

I use this code and it works perfectly. Date 11/12/2015 is disabled and users can't select it.

isInvalidDate: function(date) {
    if (date.format('YYYY-MM-DD') == '2015-11-12') {
        return true; 
    } else {
        return false; 
    }
},

But I need to add few dates to invalid, so user can't use them. I don't know how to do some array and loop through to return true or false days, could anyone help me with this?

Domagoj
  • 13
  • 1
  • 1
  • 5
  • Maybe add what language you're using (I'm presuming javascript?). Remeber that you need to validate it again on whatever server side language as well when processing the response. –  Nov 21 '15 at 23:51
  • Sorry, I forgotten, it is javascript. When I add this code two times in a row, it wont work because than is disabled only last date, not all of them – Domagoj Nov 29 '15 at 15:17

2 Answers2

9

I hope it will help someone

 var some_date_range = [
  '02-04-2016',
  '03-04-2016',
  '04-04-2016',
  '05-04-2016'
];
"isInvalidDate" : function(date){
  for(var ii = 0; ii < some_date_range.length; ii++){
    if (date.format('DD-MM-YYYY') == some_date_range[ii]){
      return true;
    }
  }
}
2

You'll need a way to feed the blocked date from your backend to the client. But let's suppose you solved that and have the dates in an array. All you need to do then is to check if the date in in the array.

See e.g. here: Checking if date belongs to array of dates

To get the invalid dates from the backend you could either put them in the script itself, of have the script fetch the to be blocked dates from the server using e.g. ajax.

Don't forget to revalidate on the server, never trust filtering in the clients to actually happen.

Community
  • 1
  • 1
  • Thanks, i have solved this problem. Just used this code: if (date >= moment('2015-11-11') && date <= moment('2015-11-25')) { return true; } – Domagoj Dec 10 '15 at 06:32