Render your own fields in the edit dialog while the scheduler keeps the dialog, the recurring scope and the save.
Clicking an event, or pressing F2 on it, opens the edit dialog. By default it edits the title, start, end, color and repeat rule. You can render your own fields in their place. The dialog itself stays the same: its heading, focus handling, Escape, the Applies to select of a recurring event, and the Delete, Cancel and Save buttons.
The example below books workshop jobs: the form edits only the start and a duration, and the end follows from them.
import { Component } from '@angular/core'
import {
SchedulerComponent, SchedulerSlotDirective, type EventFormValues, type SchedulerEvent
} from '@coreui/angular-scheduler'
const pad = (n: number) => String(n).padStart(2, '0')
const day = (offset: number) => {
const date = new Date()
date.setDate(date.getDate() - ((date.getDay() + 6) % 7) + offset)
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
}
const minutesBetween = (start: string, end: string) => (new Date(end).getTime() - new Date(start).getTime()) / 60_000
const addMinutes = (value: string, minutes: number) => {
const date = new Date(value)
date.setMinutes(date.getMinutes() + minutes)
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`
}
@Component({
selector: 'docs-scheduler-edit-dialog-example',
imports: [SchedulerComponent, SchedulerSlotDirective],
template: `
<c-scheduler [dayStartHour]="7" [dayEndHour]="18" [events]="events">
<ng-template cSchedulerSlot="eventForm" let-event="event" let-labels="labels" let-setValues="setValues" let-values="values">
<label class="scheduler-dialog-field">
<span class="scheduler-dialog-label">{{ labels.startLabel }}</span>
<input
class="form-control form-control-sm"
required
type="datetime-local"
[value]="values.start"
(input)="setValues(moveStart($any($event.target).value, values, event))"
/>
</label>
<label class="scheduler-dialog-field">
<span class="scheduler-dialog-label">Duration</span>
<select
class="form-select form-select-sm"
(change)="setValues({ end: addMinutes(values.start, +$any($event.target).value) })"
>
@for (minutes of durationsFor(duration(values, event)); track minutes) {
<option [selected]="minutes === duration(values, event)" [value]="minutes">{{ minutes }} min</option>
}
</select>
</label>
</ng-template>
</c-scheduler>
`
})
export class SchedulerEditDialogExample {
readonly addMinutes = addMinutes
readonly durations = [30, 60, 90, 120]
readonly events = [
{
id: 'service', title: 'Annual service', start: `${day(1)}T09:00`, end: `${day(1)}T10:30`
},
{
id: 'tyres', title: 'Tyre change', start: `${day(2)}T13:00`, end: `${day(2)}T13:30`, color: '#2eb85c'
}
]
duration(values: EventFormValues, event: SchedulerEvent): number {
const measured = minutesBetween(values.start, values.end)
return measured > 0 ? measured : minutesBetween(event.start, event.end)
}
durationsFor(duration: number): number[] {
return this.durations.includes(duration) ? this.durations : [...this.durations.filter(minutes => minutes < duration), duration, ...this.durations.filter(minutes => minutes > duration)]
}
moveStart(start: string, values: EventFormValues, event: SchedulerEvent): Partial<EventFormValues> {
return start ? { start, end: addMinutes(start, this.duration(values, event)) } : { start }
}
}Custom form
Put an <ng-template cSchedulerSlot="eventForm"> inside <c-scheduler> and
import SchedulerSlotDirective. The template renders inside the dialog’s form
and its context carries:
| Name | Type | Description |
|---|---|---|
allDay | boolean | Whether the edited occurrence is all-day. |
event | SchedulerEvent | The event being edited, without the changes made in the dialog. |
labels | SchedulerLabels | The labels of this scheduler, including your overrides. |
recurring | boolean | Whether the occurrence belongs to a recurring event. |
setValues | (values) => void | Merges the given keys into the dialog values. |
values | EventFormValues | The current dialog values (below). |
<c-scheduler [events]="events">
<ng-template cSchedulerSlot="eventForm" let-labels="labels" let-setValues="setValues" let-values="values">
<label class="scheduler-dialog-field">
<span class="scheduler-dialog-label">{{ labels.startLabel }}</span>
<input
class="form-control form-control-sm"
type="datetime-local"
[value]="values.start"
(input)="setValues({ start: $any($event.target).value })"
/>
</label>
</ng-template>
</c-scheduler>Values
| Key | Type | Description |
|---|---|---|
start | string | Start as wall-clock time in the scheduler timeZone (YYYY-MM-DDTHH:mm), or a date (YYYY-MM-DD) for an all-day event. |
end | string | End, in the same form as start. |
title | string | undefined | Event title. A blank title is saved as undefined. |
color | string | undefined | Event color. |
rrule | string | undefined | Repeat rule without the RRULE: prefix. An empty rule is saved as undefined. |
meta | object | undefined | Your own data on the event. setValues({ meta }) replaces the whole object, so spread event.meta to keep the rest. |
Saving
Save writes the values over the event and keeps everything they do not carry,
such as id, resourceId, allDay and exdates. An end at or before the
start keeps the duration the event had. The change reaches onEventChange
and dataSource.persistEvents like any other edit, and for a recurring event
it applies to the scope chosen in the dialog.
Cancel, Escape and a click on the backdrop discard the values. The next time the dialog opens, they start again from the event.
Validation
Your fields sit inside the dialog’s <form>, so the browser validates them
before Save: required, min, max, pattern or setCustomValidity() on
your inputs keep the dialog open until they are valid.
Focus and styling
When the dialog opens, focus moves to the first element of your form that
can take it, or to Cancel when there is none. Wrap a field in
.scheduler-dialog-field with a .scheduler-dialog-label caption to match
the spacing and typography of the built-in fields.