2016-08-04 43 views
0

我一直在使用這個DateTime選擇器在我的網站的一部分,我有一個每週的時間表有一個開始和結束時間取決於一週的一天,我想禁用時間那是超出時間表的範圍,包括分鐘,我的驚訝是什麼?我找不到關於禁用分鐘的任何文檔。我決定改變另一個DateTime插件,但我將不得不改變我已有的所有代碼。所以我回到了[eonasdan-datetimepicker]有什麼辦法可以完成這個任務嗎?我能夠成功禁用小時,但我正在談論分鐘。如何設置禁用分鐘

回答

-1

你究竟想要什麼?比如只允許用戶選擇特定時間,如半小時[30]或整個小時? [00]因爲如果是這樣的話,你可以使用步進功能,它所做的是,當用戶選擇向上或向下箭頭時,分鐘將按照您選擇的方式前進,例如30分鐘:例如,30分鐘:

$(document).ready(function() { 
$('#datetimepicker4').datetimepicker({    
stepping:30      
       }); 
      }); 
+1

不,我不想這樣做。我希望用戶不能選擇具體的會議記錄,但並不總是相同的會議記錄,而是取決於當天。你懂。像一個時間表。 –

+0

具體而言,他需要禁用每週不同的不同分鐘間隔 – Eugenio

0

您可以使用選項disabledTimeIntervals,但這隻適用於特定日期(時刻),那麼您必須指定每個可用日期的時間間隔。我做了這樣的事情:

 var addingColacionInterval = function (disabledTimeIntervals, currDate) { 
      var intervalsPerDay = { 
       1: { //1-7 where 1 is Monday and 7 is Sunday 
        startHour:15, 
        startMinute: 40, 
        durationInMinutes: 30 
       }, 
       2: { 
        startHour:8, 
        startMinute: 20, 
        durationInMinutes: 50 
       } 
       // etc 
      } 

      var intervalForWeekDay = intervalPerDay[currDate.isoWeekday()]; //.isoWeekday(); // returns 1-7 where 1 is Monday and 7 is Sunday 
      var initialTime = currDate.clone().set({ hour: intervalForWeekDay.startHour, minute: intervalForWeekDay.startMinute }); 
      disabledTimeIntervals.push([initialTime, initialTime.clone().add(parseInt(intervalForWeekDay.durationInMinutes), 'minutes')]); 

     } 

     var minDate = moment("the min selectable date"); 
     var maxDate = moment("the max allowed date"); 

     //for disable colación minutes intervals we can't use disableHours because don't work with minutes disabledTimeIntervals doesn't work for all days (like, but you have to loop trought 
     var disabledTimeIntervals = []; 
     var currDate = minDate.clone().startOf('day'); 
     var lastDate = maxDate.clone().endOf('day'); 
     do { 
      addingColacionInterval(disabledTimeIntervals, currDate); 

     } while (currDate.add(1, 'days').diff(lastDate) < 0); 

     var disabledHours = [0, 1, 2, 3, 4, 5, 6, 7, 23]; 
     $scope.disableDays = []; 
     if ($scope.import.disableSunday) { 
      $scope.disableDays = [0]; 
     } 
     // 
     $scope.dateSecOptions = { 
      minDate: minDate.format('YYYY-MM-DD'), 
      maxDate: maxDate.format('YYYY-MM-DD'), 
      disabledHours: disabledHours, 
      disabledTimeIntervals: disabledTimeIntervals, 
      stepping: 10, 
     }; 

與disabledTimeIntervals對比也存在期權disabledHours,讓你可以禁用時間在日曆組件的所有可用(可選)天。