jdtcn / BlazorDateRangePicker

A Blazor component for choosing date ranges and dates
MIT License
182 stars 35 forks source link

Enable dates do not match #59

Closed Vokchaks closed 3 years ago

Vokchaks commented 3 years ago

I used only one calendar

            <DateRangePicker @ref="Picker" Inline="true" AutoApply="true" ShowOnlyOneCalendar="true"
                             DaysEnabledFunction="DaysEnabledFunction"
                             @bind-MinDate="MinDate" @bind-MaxDate="MaxDate"
                             @bind-StartDate="StartDate"
                             OnSelectionStart="OnSelectionStart"
                             OnMonthChangedAsync="OnMonthChangedAsync" />

but when I add the enable dates - the last date of the month is set disabled help me, please

jdtcn commented 3 years ago

Hi Vladimir,

Share your implementation of DaysEnabledFunction please, or better share the whole @code block because there is no problem with the code you posted.

And you don't need @bind- for MinDate or MaxDate because they will never be changed inside the DateRangePicker.

Vokchaks commented 3 years ago

NavMenu.razor.zip

Disable days only: 12 and 13

Screenshot 2021-03-22 060046

jdtcn commented 3 years ago

It seems there is an issue with your AData.GetDatesAsync(date) implementation, could you share it please? Also there are some non-critical issues in your code, for example:

Vokchaks commented 3 years ago

It seems there is an issue with your AData.GetDatesAsync(date) implementation, could you share it please? Also there are some >non-critical issues in your code, for example:

Why EnabledDays.Add(day) in FillDisabledDates invoked twice?

I tried both ways wirh onсe and with twice — the result is unchanged

<Why you use range selection mode if you need only single date selection? You can just use SingleDatePicker="true".

I tried this. fixed again

Attach picture afer change code

image


        async Task FillDisabledDates(DateTime date)
        {
            if (EnabledDays.Exists(d => d.DateTime.Month == date.Month))
                return;
            //Debug.WriteLine($"FILL MONTH: {month} ");
            //List<DateTime> dates = await AData.GetDatesAsync(date);
            List<DateTime> dates = octouber2019;
            foreach (var day in dates.OrderBy(d => d))
            {
                Debug.WriteLine($"DAY: {day} ");
                EnabledDays.Add(day);
             //   EnabledDays.Add(day);
            }
            Debug.WriteLine($"ENABLE DAYS COUNT: {EnabledDays?.Count} ");
        }
        List<DateTime> octouber2019 = new List<DateTime> {
            new DateTime(2019,10,01),
            new DateTime(2019,10,02),
            new DateTime(2019,10,03),
            new DateTime(2019,10,04),
            new DateTime(2019,10,05),
            new DateTime(2019,10,06),
            new DateTime(2019,10,07),
            new DateTime(2019,10,08),
            new DateTime(2019,10,09),
            new DateTime(2019,10,10),
            new DateTime(2019,10,14),
            new DateTime(2019,10,15),
            new DateTime(2019,10,16),
            new DateTime(2019,10,17),
            new DateTime(2019,10,18),
            new DateTime(2019,10,19),
            new DateTime(2019,10,20),
            new DateTime(2019,10,21),
            new DateTime(2019,10,22),
            new DateTime(2019,10,23),
            new DateTime(2019,10,24),
            new DateTime(2019,10,25),
            new DateTime(2019,10,26),
            new DateTime(2019,10,27),
            new DateTime(2019,10,28),
            new DateTime(2019,10,29),
            new DateTime(2019,10,30),
            new DateTime(2019,10,31), // !!! 
        };
     }
jdtcn commented 3 years ago

The problem is probably with the MaxDate property. Try setting MaxDate to 31.03.2019 23:59:59 please.

Vokchaks commented 3 years ago

Thanks. It fixed 31.10, but how I must to disable 30.09 ?

jdtcn commented 3 years ago

The MaxDate property has nothing to do with DaysEnabledFunction so there should be no problem.

Vokchaks commented 3 years ago

The MaxDate property has nothing to do with DaysEnabledFunction so there should be no problem.

But, it problem - the screenshot above . In list oktober2019 not present september

jdtcn commented 3 years ago

But you're only comparing the day component inside your DaysEnabledFunction:

public bool DaysEnabledFunction(DateTimeOffset day)
{
    return EnabledDays.Any(d => d.Day == day.Day);
}

then change it with something like

public bool DaysEnabledFunction(DateTimeOffset day)
{
    return EnabledDays.Any(d => d.Date == day.DateTime.Date);
}
Vokchaks commented 3 years ago

Yes! Thanks, very match