EventEdit

Feature that displays a popup containing widgets for editing event data.

Event edit
//<code-header>
fiddle.title = 'Event edit';
//</code-header>
targetElement.innerHTML = '<p>Double click an event to show the event editor, or click + drag empty area to create a new one with the editor:</p>';
const scheduler = new Scheduler({
    appendTo : targetElement,

    // makes scheduler as high as it needs to be to fit rows
    autoHeight : true,

    startDate : new Date(2018, 4, 6),
    endDate   : new Date(2018, 4, 13),

    columns : [
        { field : 'name', text : 'Name', width : 100 }
    ],

    resources : [
        { id : 1, name : 'Bernard' },
        { id : 2, name : 'Bianca' }
    ],

    events : [
        { id : 1, resourceId : 1, name : 'Double click me', startDate : '2018-05-08', endDate : '2018-05-11' }
    ]
});

To customize its contents you can:

  • Reconfigure built-in widgets by providing override configs in the items config.
  • Change the date format of the date & time fields: dateFormat and timeFormat
  • Configure provided widgets in the editor and add your own in the items config.
  • Remove fields related to recurring events configuration (such as recurrenceCombo) by setting showRecurringUI config to false.
  • Advanced: Reconfigure the whole editor widget using editorConfig

Built-in widgets

The built-in widgets are:

Widget ref Type Weight Description
nameField TextField 100 Edit name
resourceField ResourceCombo 200 Pick resource(s)
startDateField DateField 300 Edit startDate (date part)
startTimeField TimeField 400 Edit startDate (time part)
endDateField DateField 500 Edit endDate (date part)
endTimeField TimeField 600 Edit endDate (time part)
recurrenceCombo RecurrenceCombo 700 Select recurrence rule (only visible if recurrence UI is enabled)
editRecurrenceButton RecurrenceLegendButton 800 Edit the recurrence rule (only visible if recurrence is used)
colorField ¹ EventColorField 700 Choose background color for the event bar

¹ Set the showEventColorPickers config to true to enable this field

Date and time fields

The date and time fields both keep the full date and time value of the event's start and end instant.

The date and time fields are partner linked pairs. Changing one will update the other to keep the full date/time value.

The start and end instants of the event are kept consistent while editing. Changing the start date/time will adjust the end date/time to keep the same duration.

The min of the end fields is kept in sync to be no earlier than the start instant.

The built-in buttons are:

Widget ref Type Weight Description
saveButton Button 100 Save event button on the bbar
deleteButton Button 200 Delete event button on the bbar
cancelButton Button 300 Cancel event editing button on the bbar

Removing a built-in item

To remove a built-in widget, specify its ref as null in the items config:

const scheduler = new Scheduler({
    features : {
        eventEdit : {
            items : {
                // Remove the start time field
                startTimeField : null
            }
        }
    }
})

Bottom buttons may be hidden using the bbar config passed to editorConfig:

const scheduler = new Scheduler({
    features : {
        eventEdit : {
            editorConfig : {
                bbar : {
                    items : {
                        deleteButton : null
                    }
                }
            }
        }
    }
})

To remove fields related to recurring events configuration (such as recurrenceCombo), set showRecurringUI config to false.

Customizing a built-in widget

To customize a built-in widget, use its ref as the key in the items config and specify the configs you want to change (they will merge with the widgets default configs):

const scheduler = new Scheduler({
    features : {
        eventEdit : {
            items : {
                // ref for an existing field
                nameField : {
                    // Change its label
                    label : 'Description'
                }
            }
        }
    }
})

Adding custom widgets

To add a custom widget, add an entry to the items config. The name property links the input field to a field in the loaded event record:

const scheduler = new Scheduler({
    features : {
        eventEdit : {
            items : {
                // Key to use as fields ref (for easier retrieval later)
                color : {
                    type  : 'combo',
                    label : 'Color',
                    items : ['red', 'green', 'blue'],
                    // name will be used to link to a field in the event record when loading and saving in the editor
                    name  : 'eventColor'
                }
            }
        }
    }
})

Video guides

For more info on customizing the event editor, please see "Customize event editor" guide.

This feature is enabled by default

Configs

23

Common

disabledInstancePlugin
listenersEvents

Editor

The configuration for the internal editor widget. With this config you can control the type of editor (defaults to Popup) and which widgets to show, change the items in the bbar, or change whether the popup should be modal etc.

const scheduler = new Scheduler({
    features : {
        eventEdit  : {
            editorConfig : {
                modal  : true,
                cls    : 'my-editor' // A CSS class,
                items  : {
                    owner : {
                        weight : -100, // Will sort above system-supplied fields which are weight 100 to 800
                        type   : 'usercombo',
                        name   : 'owner',
                        label  : 'Owner'
                    },
                    agreement : {
                        weight : 1000, // Will sort below system-supplied fields which are weight 100 to 800
                        type   : 'checkbox',
                        name   : 'agreement',
                        label  : 'Agree to terms'
                    },
                    resourceField : {
                        // Apply a special filter to limit the Combo's access
                        // to resources.
                        store  {
                            filters : [{
                                filterBy(resource) {
                                    return shouldShowResource(record);
                                }
                            }]
                        }
                    }
                },
                bbar : {
                    items : {
                        deleteButton : {
                            hidden : true
                        }
                    }
                }
            }
        }
    }
});

Or to use your own custom editor:

const scheduler = new Scheduler({
    features : {
        eventEdit  : {
            editorConfig : {
                type : 'myCustomEditorType'
            }
        }
    }
});

A CSS selector targeting elements that should not trigger the editor when clicked.

triggerEvent: String= eventdblclick

The event that shall trigger showing the editor. Defaults to eventdblclick, set to '' or null to disable editing of existing events.

typeField: String= eventType

The data field in the model that defines the eventType. Applied as class (b-event-type-xx) to the editors element, to allow showing/hiding fields depending on eventType. Dynamic toggling of fields in the editor is activated by adding an eventTypeField field to your widget:

const scheduler = new Scheduler({
   features : {
      eventEdit : {
          items : {
              eventTypeField : {
                 type  : 'combo',
                 name  : 'eventType',
                 label : 'Type',
                 items : ['Appointment', 'Internal', 'Meeting']
              }
          }
       }
    }
});

Note, your event model class also must declare this field:

 class MyEvent extends EventModel {
     static get fields() {
         return [
             { name : 'eventType' }
         ];
     }
 }

Other

How much of a long event bar which is clipped by scrolling must be brought into view to facilitate editing.

In a horizontal Scheduler, this will bring 100 pixels of width into view.

In a vertical Scheduler, this will bring 100 pixels of height into view.

readOnly: Boolean= falseAlso a property

Specify true to put the editor in read only mode.

It will also be in read only mode if the Scheduler / Calendar is so, or if the event record is read only.

weekStartDayEditBase

Editor widgets

dateFormatEditBase
itemsEditBase
timeFormatEditBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Recurring

showRecurringUIRecurringEventEdit

Properties

34

Common

disabledInstancePlugin

Class hierarchy

isEventEdit: Boolean= truereadonly
Identifies an object as an instance of EventEdit class, or subclass thereof.
isEventEdit: Boolean= truereadonlystatic
Identifies an object as an instance of EventEdit class, or subclass thereof.
isEditBaseEditBase
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable
isRecurringEventEditRecurringEventEdit

Other

Reference to the cancel button, if used

Reference to the delete button, if used

Returns the editor widget representing this feature

Reference to the end date field, if used

Reference to the end time field, if used

The current EventModel record, which is being edited by the event editor.

isEditing: Booleanreadonly

Returns true if the editor is currently active

How much of a long event bar which is clipped by scrolling must be brought into view to facilitate editing.

In a horizontal Scheduler, this will bring 100 pixels of width into view.

In a vertical Scheduler, this will bring 100 pixels of height into view.

Reference to the name field, if used

readOnly: Boolean= falseAlso a config

Specify true to put the editor in read only mode.

It will also be in read only mode if the Scheduler / Calendar is so, or if the event record is read only.

Reference to the resource field, if used

Reference to the save button, if used

Reference to the start date field, if used

Reference to the start time field, if used

editRecurrenceButtonRecurringEventEdit
recurrenceComboRecurringEventEdit

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

31

Other

Opens an editor for the passed event. This function is exposed on Scheduler and can be called as scheduler.editEvent().

ParameterTypeDescription
eventRecordEventModel | String | Number

Event to edit or the id of the eventRecord. When a String or Number is passed, it must be the id of an event that exists in the Scheduler's event store.

resourceRecordResourceModel

The Resource record for the event. This parameter is needed if the event is newly created for a resource and has not been assigned, or when using multi assignment.

elementHTMLElement

Element to anchor editor to (defaults to events element)

LstaticLocalizable
onEvents
onAfterSaveEditBase
onBeforeSaveEditBase
relayAllEvents
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

11

Fires on the owning Scheduler after an event is successfully saved

// Adding a listener using the "on" method
eventEdit.on('afterEventSave', ({ source, eventRecord }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler instance

eventRecordEventModel

The record about to be saved

Fires on the owning Scheduler before an event is displayed in an editor. This may be listened for to allow an application to take over event editing duties. Returning false stops the default editing UI from being shown.

Be aware of that when returning false, your app must take care of the eventRecord lifecycle - for example by commiting it or removing it from the store.

// Adding a listener using the "on" method
eventEdit.on('beforeEventEdit', ({ source, eventEdit, eventRecord, resourceRecord, eventElement }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler

eventEditEventEdit

The eventEdit feature

eventRecordEventModel

The record about to be shown in the event editor.

resourceRecordResourceModel

The Resource record for the event. If the event is being created, it will not contain a resource, so this parameter specifies the resource the event is being created for.

eventElementHTMLElement

The element which represents the event in the scheduler display.

Fires on the owning Scheduler when the editor for an event is available but before it is populated with data and shown. Allows manipulating fields etc.

// Adding a listener using the "on" method
eventEdit.on('beforeEventEditShow', ({ source, eventEdit, eventRecord, resourceRecord, eventElement, editor }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler

eventEditEventEdit

The eventEdit feature

eventRecordEventModel

The record about to be shown in the event editor.

resourceRecordResourceModel

The Resource record for the event. If the event is being created, it will not contain a resource, so this parameter specifies the resource the event is being created for.

eventElementHTMLElement

The element which represents the event in the scheduler display.

editorPopup

The editor

Fires on the owning Scheduler before an event is saved. Return false to immediately prevent saving

 scheduler.on({
     beforeEventSave() {
         // prevent saving if some custom variable hasn't 123 value
         return myCustomValue === 123;
     }
 });

or a Promise yielding true or false for async vetoing.

 scheduler.on({
     beforeEventSave() {
         const
             // send ajax request
             response = await fetch('http://my-server/check-parameters.php'),
             data     = await response.json();

         // decide whether it's ok to save based on response "okToSave" property
         return data.okToSave;
     }
 });
// Adding a listener using the "on" method
eventEdit.on('beforeEventSave', ({ source, eventRecord, resourceRecords, values, context, context.async, context.finalize }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler instance

eventRecordEventModel

The record about to be saved

resourceRecordsResourceModel[]

The resources to which the event is assigned

valuesObject

The new values

contextObject

Extended save context:

context.asyncBoolean

Set this to true in a listener to indicate that the listener will asynchronously decide to prevent or not the event save.

context.finalizefunction

Function to call to finalize the save. Used when async is true. Provide false to the function to prevent the save.

Fired before the editor will load the event record data into its input fields. This is useful if you want to modify the fields before data is loaded (e.g. set some input field to be readonly)

// Adding a listener using the "on" method
eventEdit.on('eventEditBeforeSetRecord', ({ source, record }) => {

});
ParameterTypeDescription
sourceContainer

The editor widget

recordEventModel

The record

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

11

Called on the owning Scheduler after an event is successfully saved

new EventEdit({
    onAfterEventSave({ source, eventRecord }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler instance

eventRecordEventModel

The record about to be saved

Called on the owning Scheduler before an event is displayed in an editor. This may be listened for to allow an application to take over event editing duties. Returning false stops the default editing UI from being shown.

Be aware of that when returning false, your app must take care of the eventRecord lifecycle - for example by commiting it or removing it from the store.

new EventEdit({
    onBeforeEventEdit({ source, eventEdit, eventRecord, resourceRecord, eventElement }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler

eventEditEventEdit

The eventEdit feature

eventRecordEventModel

The record about to be shown in the event editor.

resourceRecordResourceModel

The Resource record for the event. If the event is being created, it will not contain a resource, so this parameter specifies the resource the event is being created for.

eventElementHTMLElement

The element which represents the event in the scheduler display.

Called on the owning Scheduler when the editor for an event is available but before it is populated with data and shown. Allows manipulating fields etc.

new EventEdit({
    onBeforeEventEditShow({ source, eventEdit, eventRecord, resourceRecord, eventElement, editor }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler

eventEditEventEdit

The eventEdit feature

eventRecordEventModel

The record about to be shown in the event editor.

resourceRecordResourceModel

The Resource record for the event. If the event is being created, it will not contain a resource, so this parameter specifies the resource the event is being created for.

eventElementHTMLElement

The element which represents the event in the scheduler display.

editorPopup

The editor

Called on the owning Scheduler before an event is saved. Return false to immediately prevent saving

 scheduler.on({
     beforeEventSave() {
         // prevent saving if some custom variable hasn't 123 value
         return myCustomValue === 123;
     }
 });

or a Promise yielding true or false for async vetoing.

 scheduler.on({
     beforeEventSave() {
         const
             // send ajax request
             response = await fetch('http://my-server/check-parameters.php'),
             data     = await response.json();

         // decide whether it's ok to save based on response "okToSave" property
         return data.okToSave;
     }
 });
new EventEdit({
    onBeforeEventSave({ source, eventRecord, resourceRecords, values, context }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler instance

eventRecordEventModel

The record about to be saved

resourceRecordsResourceModel[]

The resources to which the event is assigned

valuesObject

The new values

contextObject

Extended save context:

context.asyncBoolean

Set this to true in a listener to indicate that the listener will asynchronously decide to prevent or not the event save.

context.finalizefunction

Function to call to finalize the save. Used when async is true. Provide false to the function to prevent the save.

Called before the editor will load the event record data into its input fields. This is useful if you want to modify the fields before data is loaded (e.g. set some input field to be readonly)

new EventEdit({
    onEventEditBeforeSetRecord({ source, record }) {

    }
});
ParameterTypeDescription
sourceContainer

The editor widget

recordEventModel

The record

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1