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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Validating Slot Available in Editor Window

Thread ID:

Created:

Updated:

Platform:

Replies:

143145 Mar 6,2019 11:44 AM UTC Mar 7,2019 12:25 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: Scheduler
Stefan
Asked On March 6, 2019 11:44 AM UTC

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!

Karthigeyan Krishnamurthi [Syncfusion]
Replied On 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 
 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;