2014-07-22 26 views
1

我使用的NoGray Calendar並有下面的代碼下一個可用日期:的Javascript NoGray日曆選擇封鎖日期後發現,如果今天被封鎖

my_cal1 = new ng.Calendar({ 
    input: {date:'date1', month:'month1', year:'year1'}, 
    selected_date:new Date(),display_date:new Date(), 
    dates_off:[{date:22, month:6}, 
    events: { 
     onDateClick: function(dt) { 
      this.select_date(dt); 
     } 
    } 

但是,當它是同一天,這一天我在,它顯示爲空白。

我該如何使它顯示並尋找下一個可用日期,以便在截止日期之後開始?

的例子日曆可以在這裏找到在http://www.nogray.com/example.php?ID=260

,我想設置的區域是start_datedisplay_date下一個可用的日期,所以如果我不得不在接下來的3天爲休息日,它會顯示日期作爲這3天后的下一個可用日期。

這可以使用NoGray軟件中的函數完成,還是需要使用PHP腳本搜索下一個可用日期並輸出所需日期?

回答

1

您可以使用方法is_selectablehttp://www.nogray.com/api/calendar/is_selectable.php來檢查日期是否可選。 is_selectable返回一個數組[true | false,'reason']。下面是一個簡單的例子

my_cal1 = new ng.Calendar({ 
    input: {date:'date1', month:'month1', year:'year1'}, 
    selected_date:new Date(), 
    display_date:new Date(), 
    dates_off:[{date:22, month:6}], // you were messing a ] here 
    events: { 
     onDateClick: function(dt){ 
      this.select_date(dt); 
     }, 
     // code to check if the start date is selectable 
     onLoad: function(){ 
      var st_dt = this.get_start_date().clone(); 
      while(!this.is_selectable(st_dt)[0]){ 
       st_dt = st_dt.from_string('today + 1'); 
      } 
      // checking if no dates are selected 
      if (!ng.defined(this.get_selected_date())){ 
       this.select_date(st_dt); 
      } 
      this.set_start_date(st_dt); 
     } 
    } 
}); 
+0

我曾嘗試和與22,23,24,25和26月進行測試這種6種,7月,由於dates_off和它仍然沒有跳到下一個可用日期。這怎麼能做到呢?再次感謝你的時間。 –

+0

確保您的日期有正確的數組(注意代碼中的註釋)。這是一個現場示例http://www.nogray.com/calendar_test.php – NoGray

+0

謝謝@NoGray。那很完美。此外,第二個日曆讀取第一個選定的日期,添加7天(+7),並檢查日期沒有被阻止,如果是這樣,去下一個可用的日子,我會在哪裏添加+7和檢查下一個可用日期如果被封鎖?通常,我會有var myDate = new Date(); myDate.setDate(myDate.getDate()+ 7);但如果其他日曆上的開始日期今天不可用,並且已移至下一個可用日期,則不會生效。這將如何完成?再次感謝。 –