You can validate the target position using the onEventMoving event handler that is fired during dragging in real time (see also event moving customization). The real-time validation need to be performed synchronously on the client side.

This example forbids target positions where the event spans multiple days and ensures none of the days overlap with a weekend.

onEventMoving: (args) => {
    const { start, end } = args;

    const isWeekend = (date) => {
        const dayOfWeek = date.getDayOfWeek();
        return dayOfWeek === 0 || dayOfWeek === 6;  // Sunday or Saturday
    };

    let currentDate = start;
    let overlapsWeekend = false;

    while (currentDate < end) {
        if (isWeekend(currentDate)) {
            overlapsWeekend = true;
            break;
        }
        currentDate = currentDate.addDays(1);
    }

    if (overlapsWeekend) {
        args.allowed = false;
    }
},

On drop, you can validate the target position using the onEventMove event handler and cancel it if doesn’t meet the rules.

This validation can be asynchronous, and you can call external services (e.g. a server-side API endpoint) to perform the validation.

onEventMove: async (args) => {
    args.async = true;
    const params = {
      id: args.e.id(),
      start: args.newStart,
      end: args.newEnd,
      resource: args.newResources
    };
    const {data} = await DayPilot.Http.post("/api/checkMoveTarget", params);

    if (data.error) {
        dp.message(data.message);
        args.preventDefault();
    }
    args.loaded();
},

Availability

Availability of this feature in DayPilot editions:

LitePro
DayPilot for JavaScript
DayPilot for ASP.NET WebForms
DayPilot for ASP.NET MVC
DayPilot for Java