ion2-calendar
ion2-calendar copied to clipboard
Unable to select dates before today in Ionic 6
Ionic version: (check one with "x") [ ] 2.x [ ] 3.x [ ] 4.x
Ion2-calendar mode: (check one with "x") [ ] components mode [ ] modal mode
I'm submitting a ... (check one with "x") [ ] bug report [ ] feature request [ ] help me
Current behavior:
Expected behavior: Allow user select days starting from defined date in options value
Steps to reproduce:
I added ion2-calendar
to an Ionic 6 project, but cannot make it select a date before the current date. Setting from
to new Date('01/01/1970')
does nothing, and just disables selecting any day at all. Is this library compatible with Ionic 6?
Related code:
options: CalendarComponentOptions = {
from: new Date('01/01/1970'),
};
ngOnInit() {
if(this.rangeType !== 'day') {
this.options.pickMode = 'range';
}
}
``
**Other information:**
**Ionic info:** (run `ionic info` from a terminal/cmd prompt and paste output below):
Ionic:
Ionic CLI : 6.19.1 (C:\Users\robot\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.1.8
@angular-devkit/build-angular : 13.2.6
@angular-devkit/schematics : 13.2.6
@angular/cli : 13.2.6
@ionic/angular-toolkit : 6.1.0
Capacitor:
Capacitor CLI : 3.5.1 @capacitor/android : 3.5.1 @capacitor/core : 3.5.1 @capacitor/ios : not installed
Utility:
cordova-res : not installed globally native-run : 1.6.0
System:
NodeJS : v16.15.0 (C:\Program Files\nodejs\node.exe)
npm : 8.5.5
OS : Windows 10```
Screenshot:
Hello, I have the same problem, were you able to solve it?
I found it is working for Ionic 6. You just need to set the to: date to be a future date. For example: this.options = { color: 'secondary', from: new Date(2021, 0, 1), // days click enabled from; to: new Date(2024, 8, 15), // days click enabled to; showMonthPicker: false, daysConfig: _daysConfig, };
I took this approach to get it working:
options: CalendarModalOptions = {
pickMode: 'multi',
showMonthPicker: true,
from: moment().add(-1,'year').toDate(),
to: moment().add(1,'year').toDate()
};
I found that the "minimum" from date is 1971
const options: CalendarModalOptions = {
title: '',
from: new Date(1971, 0, 1),
to: 0,
defaultDate: new Date(),
};
If you set before 1971 it will show all elements as a disabled
const options: CalendarModalOptions = {
title: '',
from: new Date(1970, 0, 1),
to: 0,
defaultDate: new Date(),
};
Unfortunately this repository was abandoned, to solve my problems with dates before 1970 and updates, I released a new version with corrections and new features.
https://www.npmjs.com/package/@heliomarpm/ion-calendar