We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Validating Slot Available in Editor Window

Hi,
I've been looking around the samples provided for ways to stop users from creating multiple appointments in some resources. I'm aware of the methods contained in actionBegin and popupOpen.

I'm already checking if the slot is available on popupOpen. Still, a user could have selected a free spot, and then change the start/end to a conflicting time period.

However, cancelling actionBegin isn't a great option - if a user has made extensive choices, put in all data in all fields and actionBegin is cancelled, I cannot "re-open" the editor with an error message whilst keeping all the information there.

I'd prefer to validate the availability of a slot beforehand. So far I have:

Validation Rule for StartTime:
var validationSlotAvailable = new Dictionary<string, object>() { { "required", new string[] { "isSlotAvailable", "Slot must be available"} } };

JS function:
function isSlotAvailable(startTimeElement) {
     let scheduleObj = document.getElementById('YachtEJ2').ej2_instances[0];
     let startTime = startTimeElement.element.value;
     let endTime = startTimeElement.element.form.getElementsByClassName("e-end").EndTime.value; // <-- Is there a better way to obtain this?
//     let groupIndex = ? // how can I obtain the groupIndex from the editor?
     return scheduleObj.isSlotAvailable(startTime, endTime, groupIndex); 
}

I'm not quite clear how I can obtain the group index, or better yet, the whole "args.data" that is available in popupOpen. I'd be grateful if you could help me out.
Thanks!

1 Reply

KK Karthigeyan Krishnamurthi Syncfusion Team March 7, 2019 12:25 PM UTC

Hi Stefan, 
 
Thank you for contacting Syncfusion support. 
 
We can keep the editor window open with the values after setting the args,cancel to true in ActionBegin event. Please refer the below code example. 
 
<ejs-schedule id="schedule" height="520px" selectedDate="new DateTime(2019, 3, 12)" actionBegin="onActionBegin" dataBound="onDataBound"> 
    <e-schedule-eventsettings dataSource="ViewBag.appoint"> 
    </e-schedule-eventsettings> 
    <e-schedule-group resources="@ViewBag.Resources"></e-schedule-group> 
    <e-schedule-resources> 
        <e-schedule-resource dataSource="@ViewBag.Airlines" field="AirlineId" title="Airline Name" name="Airlines" textField="AirlineName" idField="AirlineId" colorField="AirlineColor" allowMultiple="false"></e-schedule-resource> 
    </e-schedule-resources> 
</ejs-schedule> 
 
function onActionBegin(args) { 
        if (args.requestType === 'eventCreate' || args.requestType === 'eventChange') { 
            var data = (args.requestType === 'eventCreate') ? args.data[0] : (args.data); 
            var groupIndex = this.eventBase.getGroupIndexFromEvent(data); 
                if (!this.isSlotAvailable(data.StartTime, data.EndTime, groupIndex)) { 
                    args.cancel = true; 
                    flag = true; 
                    alert("Slot must be available"); 
                } 
        } 
    } 
    function onDataBound() { 
        var scheduleObj = document.getElementById('schedule').ej2_instances[0]; 
        scheduleObj.eventWindow.dialogObject.beforeClose = function (args) { 
            args.cancel = flag; 
            flag = false; 
        } 
 
    } 
 
Note: It is not recommended to use isSlotAvailable function as showed. 
 
Regards, 
Karthi 
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon