Scheduler - Server side validation

In the Scheduler, how do you do Server Side validation and return a message to the user before closing the edit dialog?

An example: If we need to do conflict checking, or date checking on the server side, how do we show this in a validation summary?

Thanks

1 Reply

HB Hareesh Balasubramanian Syncfusion Team November 8, 2019 02:01 PM UTC

Hi Brain, 
 
Greetings from Syncfusion Support. 
 
We have prepared below sample to achieve server side validation by using actionBeginevent of our scheduler. Please refer it. 
 
    function onActionBegin(args) { 
        if (args.requestType == "eventCreate") { 
            // Server validation post 
            var UserData = args.data[0]; 
            $.ajax({ 
                url: '/Home/CRUDData/', 
                data: JSON.stringify(UserData), 
                type: 'POST', 
                async: false, 
                traditional: true, 
                contentType: 'application/json', 
                success: function (data) { 
                    if (data.status && data.status != "") { 
                        if (data.status != "Validation Passed") { 
                            // If server validation fail we prevent the appointment save in db by using args.cancel = true 
                            args.cancel = true; 
                            if (!ej.base.isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
                                var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
                                schObj.uiStateValues.isBlock = true; 
                            } 
                        } 
                        // Show the message in dialog 
                        dlgObj.content = data.status; 
                        dlgObj.show(); 
 
                    } 
                }, 
                failure: function (data) { 
                    alert("Failure occurred") 
                }, 
                error: function (data) { 
                    alert("Error Occurred") 
                } 
            }); 
        } 
    } 
 
    function onActionComplete(args) { 
        if (!ej.base.isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
            var diaObj = document.querySelector('.e-schedule-dialog').ej2_instances[0]; 
            var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
            schObj.uiStateValues.isBlock = false; 
            diaObj.hide(); 
        } 
    } 
 
Server: 
      [HttpPost] 
        public ActionResult CRUDData([FromBody]ScheduleEvent model) 
        { 
            var status = ""; 
            if (model != null) 
            { 
                var data = _context.ScheduleEvents.Where(app => (app.Subject == model.Subject)).ToList(); 
                if (data.Count > 0) 
                { 
                    status = "Please Save the appointment with differnt Subject. The provided subject already exist in db"; 
                } 
                else 
                { 
                    status = "Validation Passed"; 
                } 
            } 
            else 
            { 
                status = "failure"; 
            } 
            return Json(new { status = status }); 
        } 
 
Kindly try the above samples, if you have any concerns please revert us back for further assistance. 
 
Regards, 
Hareesh 
 


Loader.
Up arrow icon