如何设置禁用分钟

时间:2016-08-04 14:35:36

标签: eonasdan-datetimepicker

我一直在我网站的某个部分使用这个DateTime选择器,我每周有一个时间表,其开始和结束时间取决于星期几,我想要禁用超出时间的时间时间范围,包括分钟,我的惊喜是什么?我找不到任何关于禁用分钟的文档。我决定更改另一个的DateTime插件,但我必须更改我已经拥有的所有代码。所以我回到[eonasdan-datetimepicker]有没有办法完成这项工作?我能够成功禁用小时数,但我说的是分钟。

2 个答案:

答案 0 :(得分: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选项,允许您禁用日历小部件中所有可用(可选)天的小时数。

答案 1 :(得分:-1)

你究竟想要什么?例如,仅允许用户选择特定时间,如半小时[30]或整个小时? [00]因为如果是这种情况,您可以使用步进功能,它的作用是当用户选择向上或向下箭头时,分钟会根据您的选择前进,例如30分钟:

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