Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectDate([array]) problem #651

Open
seantw opened this issue Dec 9, 2024 · 1 comment
Open

selectDate([array]) problem #651

seantw opened this issue Dec 9, 2024 · 1 comment

Comments

@seantw
Copy link

seantw commented Dec 9, 2024

I want to pick a week:

Complete example

 function getWeek(d) {
    const date = Array.isArray(d)?d[0]:d;
    const week = date.getDay() || 7;
    const d1 = new Date(date);   
    d1.setDate(date.getDate() - (week-1));
    const d2 = new Date(d1);
    d2.setDate(d1.getDate() + 6);
    return [d1,d2];
  }
  
  new AirDatepicker('#el',{
    range: true,
    multipleDatesSeparator: ' ~ ',
    dateFormat: d=>d.toLocaleString('ja',{year:'numeric',month:'long',day:'2-digit'}), //why? Only show one date
    // dateFormat: 'yyyy-MM-dd', // The results were stable and as expected
    onSelect:({date,datepicker})=> {
      datepicker.clear({silent:true});
      datepicker.selectDate(getWeek(date),{silent:true});
    }
  });

If dateFormat is a string, it works fine.
when dateFormat is a function,
I expect selectDate() to show multiple dates,
but it's only a single date.

@t1m0n
Copy link
Owner

t1m0n commented Dec 19, 2024

Interesting case, actually I don't remember why I did it like this, but as a workaround you could add multipleDates: true, then you should get an array in dateFormat callback. But note that multipleDatesSeparator won't work in such case, you should join dates in dateFormat manually with preferable separator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants