简体   繁体   English

日期范围选择器-无效日期

[英]Date range picker - invalid date

I am using this date range picke ( http://www.daterangepicker.com/#options ) 我正在使用此日期范围选择器( http://www.daterangepicker.com/#options

Here are some of options, I understand the most but I need help about "isInvalidDate" 这些是我最了解的一些选项,但我需要有关“ isInvalidDate”的帮助

I use this code and it works perfectly. 我使用此代码,并且效果很好。 Date 11/12/2015 is disabled and users can't select it. 日期11/12/2015已禁用,用户无法选择它。

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? 我不知道如何做一些数组并循环返回真假天,有人可以帮我吗?

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;
    }
  }
}

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 eg 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 eg ajax. 为了从后端获取无效的日期,您可以将它们放在脚本本身中,或者让脚本使用例如ajax从服务器获取要阻止的日期。

Don't forget to revalidate on the server, never trust filtering in the clients to actually happen. 不要忘记在服务器上进行重新验证,永远不要相信客户端中的过滤实际发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM