為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. 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). Then i use the daterangepicker jQuery plugin, so he can selecte date ranges and change the availability values. They can only view/edit availabilities for the current and the next year.

我為一些用戶開發了一個后端,他們可以查看/編輯整個選定年份的酒店房間的可用性。我正在使用HTML / PHP / MySQL來顯示他們想要的年份的可用性值。這種形式有365個輸入(每個輸入代表一天。這意味着有365個輸入,具體取決於所選的年份)。然后我使用daterangepicker jQuery插件,這樣他就可以選擇日期范圍並更改可用性值。他們只能查看/編輯當前和下一年的可用性。

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. Current year is /0 and next year is /1. I want to display only current and next year.

為了記錄,我檢查最后一個href參數以了解所選年份。當前年份為/ 0,明年為/ 1。我想只顯示當前和明年。

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. If they view 2016, i want to limit the daterangepicker to 1st of January - 31st December of 2016 only. Same for the next year 2017 and so on.

無論如何,這是一個簡短的介紹。我想要做的是,為所選年份設置daterangepicker的最小和最大日期。如果他們查看2016年,我想將daterangepicker限制為2016年1月1日至12月31日。明年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

先謝謝你

1 个解决方案

#1


1  

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.

我個人會建議你使用某種類型的庫。通常手動執行此操作(根據我的個人經驗)並且可用的庫通常非常好。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/01/04/7908b177abc1a4ca0367d7fc14fbd6d.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com