Check pasted event before creating it

Hello Together,

I have added keyboard-support to our scheduler now. It works fine, but I allways need to check the events before creating them in the database.

The Event “onEventPasted” fires but the event is created directly after pressing CTRL-V.

Have you got any other Idea?

Kind Regards,

Sebastian

Hi Sebastian,

Try redefining the _do_paste function after the dhtmlxscheduler_key_nav.js file has been included in your code (this is the function that calls onEventPasted and adds the event), it’s current code should be something similar to:

scheduler._do_paste=function(e,t,s){scheduler.addEvent(t),scheduler.callEvent("onEventPasted",[e,t,s])}

so in a script tag you can use for example:

scheduler._do_paste=function(e,t,s){ if (scheduler.callEvent("onEventPasted",[e,t,s])) scheduler.addEvent(t) };

Regards,
Dean

That worked. Thank you very much!

I wouldn’t recommend redefining internal functions, what if the dhtmlx team change the way that works in the next version? Your app will break.

Instead, you can make use of the onEventPasted function and perhaps implement the following steps within:

  1. set the scheduler to readonly mode and show the loading cover (or implement your own)
  2. Do your checks on the event object that is passed in
  3. If the checks fail, delete the event using scheduler.deleteEvent(id) or kick some other process off such as showing the lightbox where the user can correct the data etc…

Hi smartfaceweb,

If you plan on updating to newer versions then it would be advised to instead make your changes either in a new JS file (making sure to include it after the file that you’re modifying) or solely in your own code in a script tag (like I mentioned). Otherwise you’ll need to go through and apply your changes to the new version of the scheduler when you update.
I’ve been doing this since around V2 of the scheduler with no issues, if something does change it only takes a couple of minutes to check the console log for which function is causing the issue, check over the new versions code for that function and apply the changes to your custom function.

Regards,
Dean

If that method works for you and you haven’t had any issues that’s great. I didn’t mean to come across as negative about your approach, just to offer another perspective for anyone with a similar problem in the future.

In this particular scenario, the method you are overwriting is quite simple and it is unlikely that the dhtmlx team would completely rewrite it in future versions, but I still wouldn’t make that approach a habit.

If there is a clear need to take an existing lib and change the inner workings for your specific needs, this is where you should be forking the code base.