Event data saved to database via AJAX and Custom Form Proble

Hello! I have tried for three days to solve my problem, please help.

I have a custom form, on the save button it calls the javascript function save_form(), my custom form works great as long at there is no AJAX return errors, but if AJAX returns an error, my custom form won’t close. It just stays on screen.

The line: scheduler.endLightbox(true, html(“my_form”));
works if it is just in the function, but as soon as i place it in the ajax call it stops working.

I just want to turn off the custom form using a command upon success message returned from the ajax call.

below is the entire function… (look for my comments in the code below)

function save_form() {

        var ev = scheduler.getEvent(scheduler.getState().lightbox_id);
        var event_id = ev.id;

        var caldata = "ddlStage=" + $("#ddlStage").val() ;  // I trimmed this for conciseness 
        
        $.ajax({
            type: "POST",
            async: "false",
            url: "Calendar_Save_Appointment.aspx",
            data: caldata,
            success: function (msg) {

                if (msg.length > 20) {

                    alert("There was a problem saving the data, could be just a server communication error, however, just in case check your data, then save again.");
                    
                    return 
                }
                if (msg.length > 0) {

                    scheduler.changeEventId(event_id, msg);
                    scheduler.getEvent(msg).text = eventText;
                    scheduler.updateEvent(msg);
                    clearformvals();

                    // THIS NEXT LINE IS NOT WORKING, 
                    // I WAS HOPING IT WOULD CLOSE THE CUSTOM FORM
                    scheduler.endLightbox(true, html("my_form"));
                    alert("saved");
                    return 
                }
            }
        });



                 // IF I HAVE THIS LINE OUTSIDE THE AJAX, IT WORKS.  I COMMENT OUT FOR NOW
                 // scheduler.endLightbox(true, html("my_form"));



    }

If you want just to hide form you can use

scheduler.hideCover(html(“my_form”));

As for original bug - must probably it is related to ID changing - you can try to change order of commands and call changeEventId after endLightbox - in such case all must work correctly.

Stanislav,

Thank you so much for your help. Your advise about the changing of the form id was exactly what it was. I changed the order so that I changed the eventId after I closed the form and now it works perfectly.

here is my new code…

if (msg.length > 0) {
scheduler.endLightbox(true, html(“my_form”));

                    scheduler.changeEventId(event_id, msg);
                    scheduler.getEvent(msg).text = eventText;
                    scheduler.updateEvent(msg);
                    
                    alert("saved");
                    return 
                }