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 Custom Fields

Thread ID:

Created:

Updated:

Platform:

Replies:

141966 Jan 13,2019 02:04 PM UTC Jan 14,2019 11:59 AM UTC ASP.NET Core - EJ 2 1
loading
Tags: Scheduler
Stefan
Asked On January 13, 2019 02:04 PM UTC

Hi,
I'm sorry that I have to bother you with this, I couldn't find an example in the documentation although I am sure it does exist.
In https://ej2.syncfusion.com/aspnetcore/Schedule/EditorValidation#/material is a description of how to attach validation rules to members of 
<e-eventsettings-fields>, e.g. <e-field-subject name="Subject" validation="ValidationRules"></e-field-subject>

I have added additional fields to the Editor window using the popupOpen Event; one of those is e.g. an Option to select if the appointment is open, closed or to be approved by the Owner for other people.
So now I have an e-field named ListOption, which is a DropDown of [{"Id":0,"Name":"Unknown"},{"Id":1,"Name":"Open"},{"Id":2,"Name":"Closed"},{"Id":3,"Name":"Approve"}];

On saving the Appointment, I would like to make sure that ListOption is not empty, and that the value is between 1 and 3 (ie not "None").

How can I attach that validation?
Thank you very much for your assistance. Please let me know should you require a full example and I shall provide one on stackblitz.

Vinitha Devi Murugan [Syncfusion]
Replied On January 14, 2019 11:59 AM UTC

Hi Stefan, 

Thank you for contacting Syncfusion support. 

We have checked your query and you can achieve your requirement by making use of popupOpen event. Please refer the below code example and sample link. 


@{ 
    ViewData["Title"] = "Home Page"; 
} 
 
 
<ejs-schedule id="schedule" height="550px" selectedDate="new DateTime(2018, 2, 11)" actionBegin="onActionBegin" popupOpen="onPopupOpen" editorTemplate="#EventEditorTemplate"> 
    <e-schedule-eventsettings dataSource="@ViewBag.AppointmentData"> 
    </e-schedule-eventsettings> 
</ejs-schedule> 
 
<script id="EventEditorTemplate" type="text/x-template"> 
    <table class="custom-event-editor" width="100%" cellpadding="5"> 
        <tbody> 
 
            <tr> 
                <td class="e-textlabel">List Option</td> 
                <td colspan="4"> 
                    <input type="text" id="EventType" name="EventType" class="e-field" style="width: 100%" required /> 
                </td> 
            </tr> 
            <tr> 
                <td class="e-textlabel">Subject</td> 
                <td colspan="4"> 
                    <input id="Subject" class="e-field e-input" type="text" value="" name="Subject" style="width: 100%" /> 
                </td> 
            </tr> 
            <tr> 
                <td class="e-textlabel">Start Time</td> 
                <td colspan="4"> 
                    <input id="StartTime" class="e-field" type="text" name="StartTime" /> 
                </td> 
            </tr> 
            <tr> 
                <td class="e-textlabel">End Time</td> 
                <td colspan="4"> 
                    <input id="EndTime" class="e-field" type="text" name="EndTime" /> 
                </td> 
            </tr> 
            <tr> 
                <td class="e-textlabel">Description</td> 
                <td colspan="4"> 
                    <textarea id="Description" class="e-field e-input" name="Description" rows="3" cols="50" 
                              style="width: 100%; height: 60px !important; resize: vertical"></textarea> 
                </td> 
            </tr> 
        </tbody> 
    </table> 
</script> 
<script type="text/javascript"> 
    function onActionBegin(args) { 
        if (args.requestType === 'eventCreate' || args.requestType === 'eventChange') { 
            var data; 
            if (args.requestType === 'eventCreate') { 
                data = args.data[0]; 
            } else if (args.requestType === 'eventChange') { 
                data = args.data; 
            } 
            var scheduleObj = document.getElementById('schedule').ej2_instances[0]; 
            if (!scheduleObj.isSlotAvailable(data.StartTime, data.EndTime)) { 
                args.cancel = true; 
            } 
        } 
    } 
 
    function onPopupOpen(args) { 
        if (args.type === 'Editor') { 
            if (typeof (document.getElementById("EventType_Error")) == 'undefined') { 
                document.getElementById("EventType_Error").style.display = "none"; 
            } 
            var formElement = args.element.querySelector('.e-schedule-form'); 
            var statusElement = args.element.querySelector('#EventType'); 
            if (!statusElement.classList.contains('e-dropdownlist')) { 
                var dropDownListObject = new ej.dropdowns.DropDownList({ 
                    placeholder: 'Choose status', value: statusElement.value, 
                    fields: { text: 'Value', value: 'Id' }, 
                    dataSource: [{ "Id": 0, "Value": "Unknown" }, { "Id": 1, "Value": "Open" }, { "Id": 2, "Value": "Closed" }, { "Id": 3, "Value": "Approve" }], 
                    change: function () { 
                        if (typeof (document.getElementById("EventType_Error")) != 'undefined') { 
                            document.getElementById("EventType_Error").style.display = "none"; 
                        } 
                    } 
                }); 
 
                dropDownListObject.appendTo(statusElement); 
                statusElement.setAttribute('name', 'EventType'); 
            } 
 
            var startElement = args.element.querySelector('#StartTime'); 
            if (!startElement.classList.contains('e-datetimepicker')) { 
                new ej.calendars.DateTimePicker({ value: new Date(startElement.value) || new Date() }, startElement); 
            } 
            var endElement = args.element.querySelector('#EndTime'); 
            if (!endElement.classList.contains('e-datetimepicker')) { 
                new ej.calendars.DateTimePicker({ value: new Date(endElement.value) || new Date() }, endElement); 
            } 
            // Add the custom validation message to the dropdown 
            var validator = (formElement).ej2_instances[0]; 
            validator.addRules('EventType', { required: true }); 
        } 
    } 
</script> 
 
@*Alignment CSS for error message*@ 
<style type="text/css"> 
    .e-tooltip-wrap.e-schedule-error { 
        top: 38px !important; 
        margin-left: 200px; 
    } 
</style> 
 
 
 


Regards, 
M.Vinitha devi.

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

;