Search code examples
javascriptdhtmldhtmlx

How to add recurring events pragmatically in DHTMLX Scheduler?


I'd like to add this event to my calendar

let eventID = scheduler.addEvent({
                        start_date: "2018-03-03 10:00:00",
                        end_date: "2018-03-10 11:00:00",
                        text: "words",
                        details: "",
                        rec_type: "week_1___1,2",
                    });

However, when I run through that part of my code I get an error in dhtmlxscheduler.js Cannot read property 'valueOf' of undefined. What's the proper way to add an event as recurring. I've added the dependency js file for recurring events and specified the following in my init

    scheduler.config.details_on_create=true;
    scheduler.config.details_on_dblclick=true;
    scheduler.config.include_end_by = true;
    scheduler.config.repeat_precise = true;        
    var today = new Date(); 
    scheduler.init('scheduler_here',today, "week"); 

Solution

  • If you use addEvent for recurring events, the value of the start/end_date properties must have the Date type:

    let eventID = scheduler.addEvent({
      id: '1',
      start_date: new Date(2018, 2, 3, 10), 
      end_date:   new Date(2018, 2, 10, 11),      
      text:"words",
      details: "",
      rec_type: "week_1___1,2",
      event_pid: "0",
      event_length: 60*60*4
    })