Drag create event - custom time

In dhtmlxScheduler there is a way of creating new event by drag and drop in the calendar.

In the “month” view I want enable the user to create an event this way with default time, eg. start_date 00:00 and end_date 23:59 where start_date is the day the drag started from and end_date is the day when the mouse button was released. In other words, if the user drags and creates a new event starting from 5th of August and ending on 7th of August, I want jim/her to have lightbox displayed with the dates of August 5, 00:00 and August 7, 23:59.

How can I do that?

You can use onEventCreated handler to modify properties of new event

scheduler.attachEvent("onEventCreated", function(id){ var ev = scheduler.getEvent(); ev.start_date.setHours(0); ev.start_date.setMinutes(0); //same for end date });

Thank you Stanislav.

I am afraid it won’t work in my case. Two reasons for that:

  1. onEventCreated event fires up when you START dragging and does not when you end the drag
  2. When event is created by drag and drop (in a month view) the end date that shows up in the lightbox after that is the NEXT DAY with 00:00 hours - the next day is the day AFTER the day you stopped dragging, eg. you start dragging from August 1st and stop at August 5th - then the lightbox shows up with the start day of August 1st and the end day of August 6th (00:00). What I need is to have the end date in the lighbox to be then August 5th (23:59) - that I cannot change from onEventCreated since there is no end date set when the event fires up

Is there a way to do that with another event that occurs when drag & drop is complete? or maybe via scheduler config settings?

(1) Yep, was my mistake, but you can switch to different event

scheduler.attachEvent("onBeforeEventChanged", function(ev, e, is_new){ if (is_new){ ev.start_date.setHours(0); ev.start_date.setMinutes(0); //same for end date } });

(2) inside onBeforeEventChanged you will have both ev.start_date and ev.end_date

onBeforeEventChanged will fire when dnd process is ended but before data saving or lightbox showing.

Ok, great thanks Stanislav - it did the trick. :smiley:

Cheers!