You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FullCalendar v3中minTime未影响月/周/日视图新建事件起始时间问题

FullCalendar v3: minTime Doesn't Affect Default Start Time in Add Event Form

Let's break down why your minTime setting isn't affecting the start time in your add event form, and how to fix it.

First: What minTime Actually Does

The minTime option in FullCalendar v3 only controls the visible time range displayed on the calendar (like hiding hours before 7 AM in agenda views). It does not automatically adjust the raw start timestamp returned by the select callback when you click on a date or time slot.

When you click on a day in month/week/day views, FullCalendar defaults to returning the start of that day (00:00:00) as the start value, regardless of your minTime setting.

Why Your Attempt Didn't Work

You tried converting the adjusted time to a formatted string with .format('DD/MM/YYYY HH:mm A'), but FullCalendar's event objects expect start and end to be Moment.js objects or native Date objects—not string values. By formatting it as a string, you broke the date/time functionality that the modal/form relies on.

Fix: Adjust the Start Time in the Select Callback

Instead of converting to a string, modify the Moment.js object directly, then assign it to selectedEvent.start. Here's how to adjust your select callback:

select: function (start, end) {
    $('#hdEventID').val(0);
    $('#txtFirstName').val('');
    $('#txtLastName').val('');
    $("#txtCustomerId").val(0);
    $("#txtPhone").val('');

    // Get minTime from calendar config to keep code consistent
    const minTime = $('#calender').fullCalendar('option', 'minTime');
    const minDuration = moment.duration(minTime);
    
    // Create a copy of the start moment to avoid modifying the original
    const adjustedStart = moment(start);
    // Check if selected start is earlier than minTime on the same day
    if (adjustedStart.hours() < minDuration.hours() || 
        (adjustedStart.hours() === minDuration.hours() && adjustedStart.minutes() < minDuration.minutes())) {
        // Set start time to minTime
        adjustedStart.hours(minDuration.hours()).minutes(minDuration.minutes()).seconds(minDuration.seconds());
    }

    selectedEvent = {
        eventID: 0,
        fullName: '',
        lastName: '',
        firstName: '',
        description: '',
        allDay: false,
        start: adjustedStart, // Keep as Moment object, not string
        end: moment(adjustedStart).add($('#calender').fullCalendar('option', 'defaultTimedEventDuration')),
        color: '',
        Custd: 0
    };

    modaltest();
    openAddEditForm();
}

Key Notes:

  • Keep dates as Moment objects: Only format dates into strings when you need to display them in your form inputs (e.g., in openAddEditForm, you can use selectedEvent.start.format('DD/MM/YYYY HH:mm A') to populate the field).
  • Reuse config values: Pull minTime and defaultTimedEventDuration directly from the calendar's options instead of hardcoding—this ensures consistency if you ever update your calendar settings.
  • Conditional adjustment: Only change the start time if it's earlier than your minTime—so users who select a time after 7 AM keep their original selection.

内容的提问来源于stack exchange,提问作者nnmmss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 12:22:53