air-datepicker icon indicating copy to clipboard operation
air-datepicker copied to clipboard

[BUG] Option `selectedDates` doesnt work for all date in the same month (from the maxDate) earlier than year of maxDate (when `maxDate` is today)

Open BariqDharmawan opened this issue 1 year ago • 5 comments

I've using selectedDates to select a date on month June 2022. Today (the day this issue created) is 19 June 2023

const plainDate= '07 Jun 2022'

new AirDatepicker('#myInput', {
            maxDate: new Date(),
            locale: localeEn,
            dateFormat: "dd MMM yyyy",
            position: "top right",
            selectedDates: [DateTime.fromISO(new Date(plainDate).toISOString()).toFormat('yyyy-LL-dd')]
});

It's not selected (const plainDate= '07 Jun 2022')

image

This is also not selected (const plainDate= '07 Jun 2021')

image

But when i change it to const plainDate= '07 Jun 2023' (which is current year before maxDate) it's work

image

Or const plainDate= '07 Jul 2022' (1 year earlier than maxDate) also work

image

Or const plainDate= '07 May 2022' (1 year earlier than maxDate) also work

image

I dont know the "main bug" of this. I cant test all the date exist in this world

BariqDharmawan avatar Jun 19 '23 07:06 BariqDharmawan

@BariqDharmawan actually it is selected, just not visible. You should set view date manually by providing it to startDate or by using method setViewDate (https://air-datepicker.com/ru/methods?scrollTo=setViewDate)

t1m0n avatar Jun 22 '23 19:06 t1m0n

But why when the value is current month current year (07 Jun 2023) in my example, when this issue created, it's selected and visible, without using setViewDate? Perhaps i could contribute to fix this

BariqDharmawan avatar Jul 01 '23 12:07 BariqDharmawan

It's because calendar is already displays current date and there is no need to change the view date.

t1m0n avatar Jul 02 '23 14:07 t1m0n

I'm also having issues with "selectedDates" not working. Totally stuck! Using v2.2.3 and example code below. All works apart from "selectedDates", Its completely ignored. I need multiple dates to be selected as part of the page loading.

<input type="text" id="Calendar1" name="Calendar1" data-inline="true" data-language="en" data-date-format="yyyy-mm-dd" class="" />

<script> $('#Calendar1').datepicker({ startDate: '2023-09-01', multipleDates: true, selectedDates: ['2023-09-05', '2023-09-22'], firstDay: 1, clearButton: true, }); </script>

Any ideas? Appreciate the help, thanks.

blandyuk avatar Jan 17 '24 10:01 blandyuk

Seems v2.2.3 does not support "selectedDates". v3.4.0 works OK, but I have another issue where it keeps showing the latest date, for example, I have 8 dates selected for Nov 2023 and 1 date in Dec 2023. My "startDate" for the calendar is "2023-11-5" which should show the Nov 2023 calendar... but it doesn't, it shows Dec 2023. This is incorrect. Any fix?

blandyuk avatar Jan 17 '24 14:01 blandyuk