EventEdit
Feature that displays a popup containing widgets for editing event data.
//<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 tofalse. - 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
Configs
23Editor
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.
The event that shall trigger showing the editor. Defaults to eventdblclick, set to '' or null to
disable editing of existing events.
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.
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.
Misc
Recurring
Properties
34
Properties
34Common
Class hierarchy
Other
Reference to the cancel button, if used
Reference to the delete button, if used
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.
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.
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
Functions
31
Functions
31Other
Opens an editor for the passed event. This function is exposed on Scheduler and can be called as
scheduler.editEvent().
| Parameter | Type | Description |
|---|---|---|
eventRecord | EventModel | 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. |
resourceRecord | ResourceModel | 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. |
element | HTMLElement | Element to anchor editor to (defaults to events element) |
Configuration
Events
Misc
Events
11
Events
11Fires on the owning Scheduler after an event is successfully saved
// Adding a listener using the "on" method
eventEdit.on('afterEventSave', ({ source, eventRecord }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler instance |
eventRecord | EventModel | 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.
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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
eventEdit | EventEdit | The eventEdit feature |
eventRecord | EventModel | The record about to be shown in the event editor. |
resourceRecord | ResourceModel | 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. |
eventElement | HTMLElement | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
eventEdit | EventEdit | The eventEdit feature |
eventRecord | EventModel | The record about to be shown in the event editor. |
resourceRecord | ResourceModel | 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. |
eventElement | HTMLElement | The element which represents the event in the scheduler display. |
editor | Popup | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler instance |
eventRecord | EventModel | The record about to be saved |
resourceRecords | ResourceModel[] | The resources to which the event is assigned |
values | Object | The new values |
context | Object | Extended save context: |
context.async | Boolean | Set this to |
context.finalize | function | Function to call to finalize the save. Used when |
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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Container | The editor widget |
record | EventModel | The record |
Event handlers
11
Event handlers
11Called on the owning Scheduler after an event is successfully saved
new EventEdit({
onAfterEventSave({ source, eventRecord }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler instance |
eventRecord | EventModel | 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.
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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
eventEdit | EventEdit | The eventEdit feature |
eventRecord | EventModel | The record about to be shown in the event editor. |
resourceRecord | ResourceModel | 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. |
eventElement | HTMLElement | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
eventEdit | EventEdit | The eventEdit feature |
eventRecord | EventModel | The record about to be shown in the event editor. |
resourceRecord | ResourceModel | 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. |
eventElement | HTMLElement | The element which represents the event in the scheduler display. |
editor | Popup | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler instance |
eventRecord | EventModel | The record about to be saved |
resourceRecords | ResourceModel[] | The resources to which the event is assigned |
values | Object | The new values |
context | Object | Extended save context: |
context.async | Boolean | Set this to |
context.finalize | function | Function to call to finalize the save. Used when |
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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Container | The editor widget |
record | EventModel | The record |