0

I want to create some events on my DayPilot scheduler using my own modal window. It works fine when creating the first event. After that the event gets doubled, tripled and so on along with the new created events. It seems like args is not getting empty. Here is my code for onTimeRangeSelected:

    dp.onTimeRangeSelected = function (args) {

$('#myModal').show();
  
$('.schedule_option').click(function(){
        $('#myModal').hide();
        dp.clearSelection();
        var txt=this.getAttribute("arg");
        var colour = this.style.backgroundColor;
        var e = new DayPilot.Event({
            start: args.start,
            end: args.end,
            id: DayPilot.guid(),
            resource: args.resource,
            text: txt,
            backColor:colour
        });
        
        
        var params = {
                    start: args.start,
                    end: args.end,
                    text: txt,
                    backColor:colour,
                    id:DayPilot.guid(),
                    resource: args.resource
                };
                
        DayPilot.Http.ajax({
                    url: "admin/backend_create.php",
                    method: "POST",
                    data: params,
                    success: function(ajax) {
                        dp.message("succes");
                        
                    },
                     error: function(ajax) {
                     dp.message("Saving failed");
      }
                });     
        dp.events.add(e); 
}); 
  
}

And the effect I am getting is:

enter image description here

The modal contains 3 buttons corresponding to each event to be scheduled type.

If I use DayPilot modal I don't have issues. I can't find an explanation because somehow it worked until last Friday.

Thanks!

1 Answers1

1

Ok. I found the issue. It's the click event handler that it is being added every time a time range it's selected. I will have to get it out of there and find another way to use my own modal.