简体   繁体   English

为Daterangepicker设置每年的最小值最大值

[英]Set min max values per year for Daterangepicker

Although i have found some general answers to my question, i couldn't find any which solves my specific problem. 尽管我已找到问题的一些一般性答案,但找不到解决我特定问题的方法。

I have developed a backend for some users, where they can view/edit the availability of their hotel rooms for the whole selected year. 我已经为一些用户开发了一个后端,他们可以在其中查看/编辑整个选定年份的酒店客房可用性。 I am using HTML/PHP/MySQL to display the availability values of the year they want. 我正在使用HTML / PHP / MySQL来显示他们想要的年份的可用性值。 There are 365 inputs in this form (each input represents a single day. That means that there are 365 inputs, depending on the selected year). 此格式有365个输入(每个输入代表一天。这意味着有365个输入,具体取决于所选的年份)。 Then i use the daterangepicker jQuery plugin, so he can selecte date ranges and change the availability values. 然后,我使用daterangepicker jQuery插件,因此他可以选择日期范围并更改可用性值。 They can only view/edit availabilities for the current and the next year. 他们只能查看/编辑可用性对当前下一年度。

I let them switch from current year to next year and backwards with this code: 我让他们从当前年份切换到明年,并使用此代码向后切换:

<a class="btn btn-primary" href="https://domain.com/backend/availability/edit_availability/11/0">2016</a>
<a class="btn btn-default" href="https://domain.com/backend/availability/edit_availability/11/1">2017</a>

For the record, i check the last href parameter to understand the selected year. 作为记录,我检查了最后一个href参数以了解所选的年份。 Current year is /0 and next year is /1. 本年是/ 0,下一年是/ 1。 I want to display only current and next year. 我只想显示当前和明年。

With the below code they select a date range, set the availability number and 'Fill' the calendar with the given availability number: 他们使用以下代码选择日期范围,设置可用性编号,并使用给定的可用性编号“填充”日历:

<input id="availability_dates" class="form-control" type="text" required="required" value="" name="availability_dates">
<input id="availability_number" class="form-control col-md-7 col-xs-12" type="text" name="availability_number">
<button id="fill-availabilities" class="btn btn-success" type="submit">Fill</button>

<script>
$('#availability_dates').daterangepicker(
 {
    format: 'DD/MM/YYYY'
 }, function (start, end, label) {
    console.log(start.toISOString(), end.toISOString(), label);
 });
</script>

I grab his desired year like this: 我像这样抓住他想要的年份:

<?php
if ($year == '0') {
   $display_year = date('Y');
   $other_year = date('Y', strtotime('+1 year'));
} else {
   $display_year = date('Y', strtotime('+1 year'));
   $other_year = date('Y');
}
?>

Anyway, that's a sort briefing. 无论如何,那是一种简报。 What i am trying to do is, set the minimum and maximum dates to the daterangepicker just for the selected year . 我想做的是, 仅将所选年份的最小和最大日期设置为daterangepicker。 If they view 2016, i want to limit the daterangepicker to 1st of January - 31st December of 2016 only. 如果他们查看2016,我想将daterangepicker限制为2016年1月1日至12月31日。 Same for the next year 2017 and so on. 明年2017年依此类推,依此类推。

As you can see, years are grabbed dynamically, so i need a "script" where the daterangepicker will work even if we are in 2018 or 2020 etc. 如您所见,年份是动态获取的,所以我需要一个“脚本”,即使我们在2018年或2020年等,daterangepicker也将起作用。

I'm sorry for the long post, i've tried to explain a lot more than needed in case someone has a better solution/idea. 对于很长的帖子,我感到很抱歉,如果有人有更好的解决方案/想法,我已经尝试了很多解释。

Thank you in advance 先感谢您

I personally would recommend you using some sort of library for that. 我个人建议您为此使用某种库。 Usually is a mess to manually do that (in my personal experience) and the libraries available are usually quite good. 手动操作通常很麻烦(以我的个人经验),可用的库通常都很好。

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

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