onBeforeEventChanged event calling twice for a single action

hi,
code inside the onBeforeEventChanged event’s function is calling twice for a single action :unamused:
please suggest how to fix this issue.

scheduler.attachEvent("onBeforeEventChanged", function(objUpdatingEvent, e, is_new,objOldEvent) { 
        if(is_new){
            return true;
        }
        try{
        //objUpdatingEvent = scheduler.getEvent(id);
        var startTime = (objUpdatingEvent.start_date).getHours() + ':' + (objUpdatingEvent.start_date).getMinutes();
        var endTime = (objUpdatingEvent.end_date).getHours() + ':' + (objUpdatingEvent.end_date).getMinutes();
        var appointmentDate = (objUpdatingEvent.start_date).getDate() + '/' + parseInt((objUpdatingEvent.start_date).getMonth() + 1) + '/' + (objUpdatingEvent.start_date).getFullYear();
        var PhoneBookId = objUpdatingEvent.PhoneBookId;
        var DoctorId = objUpdatingEvent.section_id;
        var RecordType = objUpdatingEvent.RecordType;
        var arrUpdateData = {
            strRecordType: RecordType,
            timStartTime: startTime,
            timEndTime: endTime,
            datDate: appointmentDate,
            intPhoneBookId: PhoneBookId,
            intDoctorId: DoctorId
        }
        arrUpdateData = $.toJSON(arrUpdateData);

        $.ajax({
            type: "POST",
            url: "/business_newscheduler/updateschedulingtime",
            data: "arrUpdateData=" + arrUpdateData,
            async: false,
            success: function(arrResults)
            {                
            }
        });
    }
        catch (err){
            console.log(err)
        }
        return true;
    });

thanks regards ,
nik

Hi,
the event seems working as expected in a simple example
docs.dhtmlx.com/scheduler/snippet/f299f3d2

Can you provide a demo where we could reproduce the issue?

hi,
the project is not hosted yet, so i am not able to show a working demo .

FYI :

//function for creating phonebooking (single click) scheduler.attachEvent("onEmptyClick", function(date, native_event) { //alert("d") glblCurrentSectionId = null; scheduler.unmarkTimespan(marked); marked = null; var objCurrentEvent = scheduler.getActionData(native_event); var fixed_date = fix_date(date); glblCurrentSectionId = objCurrentEvent['section']; scheduler.addEventNow({ start_date:date, end_date: scheduler.date.add(date, event_step, "minute"), section_id: glblCurrentSectionId }); });

the above issue is happening for this event too.

function __constructScheduler(intDepartment, intCostCenterId, arrFilterData){
//here am creating scheduler object ,
// and am writing defanitions for onEmptyClick,onBeforeEventChanged event’s function here
}

the __constructScheduler() function is calling while clicking the custom navigation buttons .
the problem happens after the navigation button press (while calling __constructScheduler() )
if we clicking the navigation button for 5 times the onBeforeEventChanged calling five times .

onBeforeEventChanged event’s function iteration may be the problem right ?

is there any way to remove the previous onBeforeEventChanged event?

i guess that may fix my issue . :slight_smile:

Hello,
do you mean that function __constructScheduler which attaches the event listeners is called multiple times? If so, then it adds additional event listener each time when called, and firing of all handlers is expected.
The simplest way to resolve the issue is to make sure that events are attached only once, e.g.

if(!scheduler._beforeEventChanged) scheduler._beforeEventChanged = scheduler.attachEvent("onBeforeEventChanged", function(..){..});

Hi ,
thanks for your suggestion .

I removed the event listener function inside the __constructScheduler() function that fixed my issue .