Getting Error when trying to use "editorTemplate" option --- Customizing event editor using template (Javascript)

Hello Team Syncfusion,

I have an issue when i try to Customize event editor using template.

I get this Error: this.parent.getEditorTemplate(...) is not a function  at e.renderFormElements

and when i do a click on cells to add ana event i have this Error : Uncaught TypeError: Cannot read property 'openEditor' of undefined

errors.PNG


And if i delete the option : 

editorTemplate: '#EventEditorTemplate',

All thing work fine.


NB : I do copy/past of the responsible code that customize event using template on your documentation

https://ej2.syncfusion.com/javascript/documentation/schedule/editor-template/#:~:text=validation%20alert%20popup.-,Customizing%20event%20editor%20using%20template,-The%20event%20editor


7 Replies

VD Vinitha Devi Murugan Syncfusion Team August 10, 2021 08:25 AM UTC

Hi Mostafa, 
 
Greetings from Syncfusion Support. 
 
We have validated your reported problem clicking on cells to add ana event throws error : Uncaught TypeError: Cannot read property 'openEditor' of undefined.. We suspect that you might missed to define editor template or there might be mismatch in template id in your application which might results the reported issue. We have shared the working sample with the latest version for your reference in the following link. 
 
var EventData = new ej.base.extend([], window.doctorsEventDatanulltrue); 
 
var scheduleObj = new ej.schedule.Schedule({ 
  width: '100%', 
  height: '550px', 
  views: ['Day''Week''WorkWeek''Month'], 
  showQuickInfo: false, 
  selectedDate: new Date(2018115), 
  editorTemplate: '#EventEditorTemplate', 
  popupOpen: function(args) { 
    if (args.type === 'Editor') { 
      var statusElement = args.element.querySelector('#EventType'); 
      if (!statusElement.classList.contains('e-dropdownlist')) { 
        var dropDownListObject = new ej.dropdowns.DropDownList({ 
          placeholder: 'Select a status', 
          value: statusElement.value, 
          dataSource: ['New''Requested''Confirmed'] 
        }); 
        dropDownListObject.appendTo(statusElement); 
      } 
      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 
        ); 
      } 
    } 
  }, 
  eventSettings: { dataSource: EventData } 
}); 
scheduleObj.appendTo('#Schedule'); 
 
  <script id="EventEditorTemplate" type="text/x-template"> 
        <table class="custom-event-editor" width="100%" cellpadding="5"> 
            <tbody> 
                <tr> 
                    <td class="e-textlabel">Summary</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">Status</td> 
                    <td colspan="4"> 
                        <input type="text" id="EventType" name="EventType" class="e-field" style="width: 100%" /> 
                    </td> 
                </tr> 
                <tr> 
                <td class="e-textlabel">From</td> 
                    <td colspan="4"> 
                        <input id="StartTime" class="e-field" type="text" name="StartTime" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="e-textlabel">To</td> 
                    <td colspan="4"> 
                        <input id="EndTime" class="e-field" type="text" name="EndTime" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="e-textlabel">Reason</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> 
 
 
Kindly try the above sample, If you still face the problem at your end, please replicate the same in above sample or share your code snippets which would help us to provide the solution at earliest 
 
Regards, 
Vinitha 



MZ Mostafa Zouhair replied to Vinitha Devi Murugan August 18, 2021 10:25 AM UTC

Thank you for your reply Vinitha,

i have an other issue :

In Scheduler exactely on Month View, the default value of AllDay checkbox is checked .
How can i replace the default value to unchecked. with javascript ES5.

And how can i create a popup schedule edit like this (image below) using template (not with add additional fields to the default editor).
create meeting.png



Additional Fields : 
- CheckBox  : Permanent Meeting
- Attached Document : File Upload 
- Waiting Room : Checkbox
- AutoMuted : Checkbox
-Video Off: Checkbox

Delegate: Checkbox === if checked need to select the name of users 
videoMeetingUrl : input that contain a url and cannot change it (not editable)


Thank you very much for your help



VD Vinitha Devi Murugan Syncfusion Team August 19, 2021 02:48 PM UTC

Hi Mustafa, 
 
Greetings from Syncfusion Support. 
 
Q1: We have validated your reported query “How can i replace the default value to unchecked. with javascript ES5” at our end. We have achieved your requirement with the help of popupOpen event of our scheduler with below code and for the same we have prepared the below sample. 
 
 
  popupOpen: function(args) { 
    if (args.type == 'Editor' && scheduleObj.currentView == 'Month' && !args.target.classList.contains("e-appointment")) { 
        args.element.querySelectorAll('.e-time-icon')[1].classList.remove('e-icon-disable');  
            args.element.querySelectorAll('.e-time-icon')[0].classList.remove('e-icon-disable');  
            args.element.querySelector('.e-time-zone-container').classList.remove('e-disable');  
            args.element.querySelector('.e-start').ej2_instances[0].format = "M/d/yy h:mm a" 
            args.element.querySelector('.e-end').ej2_instances[0].format = "M/d/yy h:mm a" 
            args.element.querySelector('.e-start').ej2_instances[0].value.setHours(900);  
            args.element.querySelector('.e-end').ej2_instances[0].value.setHours(9300);  
            args.element.querySelector('.e-start').ej2_instances[0].dataBind();  
            args.element.querySelector('.e-all-day.e-checkbox').ej2_instances[0].checked = false; 
    } 
  } 
 
Q2: We have validated your reported query “how can i create a popup schedule edit like this (image below) using template (not with add additional fields to the default editor)” at our end. We have prepared a sample to achieve your requirements with editorTemplate which can be referred from the following link  
 
 
Kindly try with the above sample and get back to us if you need any further assistance. 
 
Regards, 
Vinitha 



MZ Mostafa Zouhair August 27, 2021 08:11 AM UTC

Hello Vinitha

The last answer you sent to me, is working fine, still a little issue, is how to save Start time zone and End Time Zone to the database (data binding remotely) also when i open an already created event I need to see on the popup the last start/end time zone saved on database. 
also for the multiselect checkbox how to read data remotly and display the elements checked when we open editPopup

thank you, 
best regards


VD Vinitha Devi Murugan Syncfusion Team August 30, 2021 08:40 AM UTC

Hi Mustafa, 
 
Thanks for your update. 
 
We have validated your reported query “How to save start and end timezone fields and additional checkbox’s fields in db” and we have prepared the CRUD samples with startTimezone, endTimezone and Extra check box fields which can be downloaded from the below link. 
 
 
Controller.ts 
public JsonResult LoadData(Params param)  // Here we get the Start and End Date and based on that can filter the data and return to Scheduler 
{ 
    DateTime start = param.StartDate; 
    DateTime end = param.EndDate; 
    var data = db.ScheduleEventDatas.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList();  // Here filtering the events based on the start and end date value. 
    return Json(dataJsonRequestBehavior.AllowGet); 
} 
public class Params 
{ 
    public DateTime StartDate { getset; } 
    public DateTime EndDate { getset; } 
} 
// CRUD Actions 
[HttpPost] 
public JsonResult UpdateData(EditParams param) 
{ 
    if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments 
    { 
        var value = (param.action == "insert") ? param.value : param.added[0]; 
        int intMax = db.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1; 
        DateTime startTime = Convert.ToDateTime(value.StartTime); 
        DateTime endTime = Convert.ToDateTime(value.EndTime); 
        ScheduleEventData appointment = new ScheduleEventData() 
        { 
            Id = intMax + 1, 
            StartTime = startTime, 
            EndTime = endTime, 
            Subject = value.Subject, 
            Location = value.Location, 
            Description = value.Description, 
            IsAllDay = value.IsAllDay, 
            StartTimezone = value.StartTimezone, 
            EndTimezone = value.EndTimezone, 
            RecurrenceRule = value.RecurrenceRule, 
            RecurrenceID = value.RecurrenceID, 
            RecurrenceException = value.RecurrenceException, 
            AudioMuted = value.AudioMuted, 
            Delegate = value.Delegate, 
            VideoOff = value.VideoOff, 
            WaitingRoom = value.WaitingRoom 
        }; 
        db.ScheduleEventDatas.InsertOnSubmit(appointment); 
        db.SubmitChanges(); 
    } 
    if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment 
    { 
        var value = (param.action == "update") ? param.value : param.changed[0]; 
        var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id)); 
        if (filterData.Count() > 0) 
        { 
            DateTime startTime = Convert.ToDateTime(value.StartTime); 
            DateTime endTime = Convert.ToDateTime(value.EndTime); 
            ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id)); 
            appointment.StartTime = startTime; 
            appointment.EndTime = endTime; 
            appointment.StartTimezone = value.StartTimezone; 
            appointment.EndTimezone = value.EndTimezone; 
            appointment.Subject = value.Subject; 
            appointment.Location = value.Location; 
            appointment.Description = value.Description; 
            appointment.IsAllDay = value.IsAllDay; 
            appointment.RecurrenceRule = value.RecurrenceRule; 
            appointment.RecurrenceID = value.RecurrenceID; 
            appointment.RecurrenceException = value.RecurrenceException; 
            appointment.AudioMuted = value.AudioMuted; 
            appointment.Delegate = value.Delegate; 
            appointment.VideoOff = value.VideoOff; 
            appointment.WaitingRoom = value.WaitingRoom; 
        } 
        db.SubmitChanges(); 
    } 
    if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment 
    { 
        if (param.action == "remove") 
        { 
            int key = Convert.ToInt32(param.key); 
            ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == key).FirstOrDefault(); 
            if (appointment != nulldb.ScheduleEventDatas.DeleteOnSubmit(appointment); 
        } 
        else 
        { 
            foreach (var apps in param.deleted) 
            { 
                ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == apps.Id).FirstOrDefault(); 
                if (apps != nulldb.ScheduleEventDatas.DeleteOnSubmit(appointment); 
            } 
        } 
        db.SubmitChanges(); 
    } 
    var data = db.ScheduleEventDatas.ToList(); 
    return Json(dataJsonRequestBehavior.AllowGet); 
} 
 
 
Db Structure:  
 
 
Kindly try with the above sample and get back to us if you need any further assistance. 
 
Regards, 
Vinitha 



MZ Mostafa Zouhair September 6, 2021 03:01 PM UTC

Thank you for your reply, the solution are goood, just have another issue with the multiselect checkbox


I have an issue with multi select textbox
 i have data like : 

contactList = {
   id : 1, name: name1,
   id : 2, name: name2,
   id : 3, name: name3,
   id : 4, name: name4,
}

as data binding i use 
var dataContact = new ej.data.DataManager({
  url: window.location.origin + '/contact/getContacts',
  crudUrl: window.location.origin + '/BatchData',
  adaptor: new ej.data.UrlAdaptor(),
  crossDomain: true,
})

 let contactListEle = args.element.querySelector('#ContactDropList')
      let booleanValDelegateList = args.data['ContactDropList']
        ? args.data['ContactDropList']
        : dataContact

      if (!contactListEle .classList.contains('e-multiselect')) {
        new ej.dropdowns.MultiSelect(
          {
            dataSource: booleanValDelegateList,
            // set placeholder to MultiSelect input element
            placeholder: 'Contact',
            value: args.data['ContactDropList'],
            // set the type of mode for checkbox to visualized the checkbox added in li element.
            mode: 'CheckBox',
            // set true for enable the selectAll support.
            showSelectAll: true,
            // set the select all text to MultiSelect checkbox label.
            selectAllText: 'Select All',
            fields: { text: 'name'value: 'id' },
          },
          contactListEle 
        )
      }


i can get the data and display it first time, then when i try to edit an event i found just the id of the contact that i already saved.
for example if i save on database the name3 with id:3, then when i try to edit the event the multiselect checkbox show me just the id not the name



NR Nevitha Ravi Syncfusion Team September 7, 2021 08:19 AM UTC

Hi Mostafa, 

Thanks for your update. 

We have modified the sample with multiselect of your shared code snippet and were unable to replicate the problem at our end. Please refer to the following sample. 


 

Please ensure that you have text in name fields which is assigned to multiselect datasource. If you still face the issue, please try to replicate the issue in a sample or share event collection of scheduler and datasource applied to multiselect to validate the problem at our end. 

Regards, 
Nevitha 


Loader.
Up arrow icon