Skip to main content

DxScheduler.AppointmentFormClosing Event

Fires before the appointment form is closed.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<SchedulerAppointmentFormClosingEventArgs> AppointmentFormClosing { get; set; }

Event Data

The AppointmentFormClosing event's data class is SchedulerAppointmentFormClosingEventArgs. The following properties provide information specific to this event:

Property Description
Appointment Specifies the target appointment. Inherited from SchedulerAppointmentOperationEventArgs.
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
FormInfo Specifies the appointment form information.
FormType Specifies the appointment form type.

Remarks

The Scheduler component raises the AppointmentFormShowing/AppointmentFormClosing event before the appointment form appears/closes. The FormType event argument identifies whether an extended or compact form is used:

<DxScheduler StartDate="@DateTime.Today"
             DataStorage="@DataStorage"
             ActiveViewType="SchedulerViewType.WorkWeek"
             AppointmentFormClosing="OnAppointmentFormClosing">
    @*...*@
</DxScheduler>

@code {
    void OnAppointmentFormClosing(SchedulerAppointmentFormClosingEventArgs args) {
        if (args.FormType == SchedulerAppointmentFormType.CompactEditForm) { 
            // Respond to form closing (for instance, show an information message).
        }
    }
    // ...
}

The following example prevents users from creating reccurent appointments that occur only once:

<DxScheduler @bind-StartDate="@StartDate"
             DataStorage="@DataStorage"
             AppointmentUpdating="AppointmentUpdating"
             AppointmentInserting="AppointmentInserting"
             AppointmentFormClosing="AppointmentFormClosing">
    <DxSchedulerWeekView ShowWorkTimeOnly="true"></DxSchedulerWeekView>
</DxScheduler>
<DxPopup @bind-Visible="@AlertVisible"
         CloseOnEscape="true"
         CloseOnOutsideClick="true"
         ShowCloseButton="true"
         HeaderText="Note"
         BodyText="The recurrent appointment occurs only once. Increase the appointment count or create a regular appointment.">
</DxPopup>

@code {
    bool AlertVisible = false;
    bool ValidationFailed = false;
    DateTime StartDate { get; set; } = DateTime.Today;

    DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
        AppointmentsSource = RecurringAppointmentCollection.GetAppointments(),
        AppointmentMappings = new DxSchedulerAppointmentMappings() {
            Type = "AppointmentType",
            Start = "StartDate",
            End = "EndDate",
            Subject = "Caption",
            AllDay = "AllDay",
            Location = "Location",
            Description = "Description",
            LabelId = "Label",
            StatusId = "Status",
            RecurrenceInfo = "Recurrence"
        }
    };
    bool IsAppointmentValid(DxSchedulerAppointmentItem appointment) {
        if (appointment.IsRecurring && 
                appointment.RecurrenceInfo.Range == SchedulerRecurrenceRange.OccurrenceCount &&
                appointment.RecurrenceInfo.OccurrenceCount == 1)
            return false;
        return true;
    }

    void AppointmentUpdating(SchedulerAppointmentOperationEventArgs e) {
        if (!IsAppointmentValid(e.Appointment)) {
            e.Cancel = true;
            AlertVisible = true;
            ValidationFailed = true;
        }
    }
    void AppointmentInserting(SchedulerAppointmentOperationEventArgs e) {
        if (!IsAppointmentValid(e.Appointment)) {
            e.Cancel = true;
            AlertVisible = true;
            ValidationFailed = true;
        }
    }
    void AppointmentFormClosing(SchedulerAppointmentFormClosingEventArgs e) {
        if (ValidationFailed) {
            e.Cancel = true;
            ValidationFailed = false;
        }
    }
}
See Also