Ubiquitous event handler for DatePicker control

I note in your example for disabling dates with the DatePicker control:

https://blazor.syncfusion.com/demos/datepicker/disabled-dates?theme=fluent

that each datetime control requires its own referenced variable and event handler routine.  Is there an easier way to direct all datepicker controls to the same event handler routine?  Otherwise this adds too much code to be truly useful.

TIA,

Miles




1 Reply

SP Sureshkumar P Syncfusion Team June 3, 2022 09:57 AM UTC

Hi Miles,

You can achieve your requirement for multiple datepicker with the same handler without a component reference variable. But when disabling the dates without weekends in the popup element using renderdaycell event the year view all the months is disabled and not able to navigate the month's selection issue is replicated so we suggest you use the individual component reference to disable the specific date using renderdaycell event.

Find the code example without component reference variable:

<SfDatePicker TValue="DateTime?" >

   <DatePickerEvents TValue="DateTime?" OnRenderDayCell="@DisableDate"></DatePickerEvents>

</SfDatePicker>

 

<SfDatePicker TValue="DateTime?" >

   <DatePickerEvents TValue="DateTime?" OnRenderDayCell="@DisableDate"></DatePickerEvents>

</SfDatePicker>

 

<SfDatePicker TValue="DateTime?" >

   <DatePickerEvents TValue="DateTime?" OnRenderDayCell="@DisableDate"></DatePickerEvents>

</SfDatePicker>

 

@code {

    private void DisableDate(RenderDayCellEventArgs args)

    {

        if (((int)args.Date.DayOfWeek == 0 || (int)args.Date.DayOfWeek == 6))

        {

            args.IsDisabled = true;

        }

    }

}

 


Regards,

Sureshkumar P


Loader.
Up arrow icon