Issue with Date Range Selection and Independent Year selection for Two Calendars in svelte js

I am using Flatpickr in svelte for date range selection in my project and encountered a specific issue regarding the Independent Year selection for two calendars. Currently, when I change the year for one calendar, it changes the year for a second calendar as well. This behavior is not desirable as I need both calendars to update their years independently.

Expected Behavior:

Independent Year Updates: Each calendar should allow independent updates to the year without affecting the other calendar.
I want to select a range for more than one year like from 2015 to 2018.

the change year function

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const changeYear = (event: Event, index: number) => {
if (calendarInstance) {
const newYear = parseInt((event.target as HTMLSelectElement).value, 10);
const currentMonth = (calendarInstance.currentMonth + index) % 12;
calendarInstance.setDate(new Date(newYear, currentMonth, 1), false);
updateDropdowns(calendarInstance);
}
t
</code>
<code>const changeYear = (event: Event, index: number) => { if (calendarInstance) { const newYear = parseInt((event.target as HTMLSelectElement).value, 10); const currentMonth = (calendarInstance.currentMonth + index) % 12; calendarInstance.setDate(new Date(newYear, currentMonth, 1), false); updateDropdowns(calendarInstance); } t </code>
const changeYear = (event: Event, index: number) => {
    if (calendarInstance) {
      const newYear = parseInt((event.target as HTMLSelectElement).value, 10);
      const currentMonth = (calendarInstance.currentMonth + index) % 12;
      calendarInstance.setDate(new Date(newYear, currentMonth, 1), false);
      updateDropdowns(calendarInstance);
    }
t

he flatepikcer set-up

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const setupFlatpickr = () => {
if (typeof window !== 'undefined') {
const options = {
mode: 'range',
showMonths: 2,
prevMonthDayClass: 'prevMonthDay not-active',
defaultDate: [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), new Date()],
nextMonthDayClass: 'nextMonthDay not-active',
dateFormat: 'Y-m-d',
onChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
startDate = selectedDates[0];
endDate = selectedDates[1];
updateSelectedRangeDisplay();
},
onReady: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
calendarInstance = instance;
insertCustomDropdowns(instance);
preselectDropdowns(instance);
},
onMonthChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
updateDropdowns(instance);
},
onYearChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
updateDropdowns(instance);
},
onClose: () => {
// Handle close event if needed
isApplied.set(false);
isCancelled.set(false);
}
// Other options as needed
};
flatpickr('#dateRangePicker', options);
}
};
</code>
<code>const setupFlatpickr = () => { if (typeof window !== 'undefined') { const options = { mode: 'range', showMonths: 2, prevMonthDayClass: 'prevMonthDay not-active', defaultDate: [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), new Date()], nextMonthDayClass: 'nextMonthDay not-active', dateFormat: 'Y-m-d', onChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => { startDate = selectedDates[0]; endDate = selectedDates[1]; updateSelectedRangeDisplay(); }, onReady: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => { calendarInstance = instance; insertCustomDropdowns(instance); preselectDropdowns(instance); }, onMonthChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => { updateDropdowns(instance); }, onYearChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => { updateDropdowns(instance); }, onClose: () => { // Handle close event if needed isApplied.set(false); isCancelled.set(false); } // Other options as needed }; flatpickr('#dateRangePicker', options); } }; </code>
const setupFlatpickr = () => {
    if (typeof window !== 'undefined') {
      const options = {
        mode: 'range',
        showMonths: 2,
        prevMonthDayClass: 'prevMonthDay not-active',
        defaultDate: [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), new Date()],
        nextMonthDayClass: 'nextMonthDay not-active',
        dateFormat: 'Y-m-d',
        onChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
          startDate = selectedDates[0];
          endDate = selectedDates[1];
          updateSelectedRangeDisplay();
        },
        onReady: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
          calendarInstance = instance;
          insertCustomDropdowns(instance);
          preselectDropdowns(instance);
        },
        onMonthChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
          updateDropdowns(instance);
        },
        onYearChange: (selectedDates: Date[], dateStr: string, instance: FlatpickrInstance) => {
          updateDropdowns(instance);
        },
        onClose: () => {
          // Handle close event if needed
          isApplied.set(false);
          isCancelled.set(false);
        }
        // Other options as needed
      };

      flatpickr('#dateRangePicker', options);
    }
  };

Any Help Would Be Appreciated:

Your assistance in resolving this issue or providing guidance on how to achieve independent year updates for two Flatpickr calendars would be greatly appreciated. Thank you!

Git Issue Link:https://github.com/flatpickr/flatpickr/issues/3025

I’m trying to selecet date range for more then 1 year in svelet js I’m using flate Date picker as of now i’m only abel to selecet range for 1 year

New contributor

Parth Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật