-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already include this feature request, without success.
Describe the Feature Request
A new flag on ion-datetime
picker to specifically control the maximum selectable year in the absence of yearValues
or a max
.
Describe the Use Case
The current default only allows for dates with years to be selected in the past. A lot of business logic cases involve both the potential to select both past and future dates to be selected 5, 10, 15 years into the future. Setting this flag allows for the year wheel to allow for future years without specifying a large list of values in yearValues.
Future dates seems to be a really ha
Describe Preferred Solution
A flag maxYearValue
to be used as a fallback in the absence of yearValues
or max
which allows for the year wheel to have future years simply without an exhaustive yearList
.
Describe Alternatives
Currently there is a work around in yearList
as,
Array.from({length: 100 + maxYearValue}, (_, i) => new Date().getFullYear() - 100 + i);
Related Code
ionic-framework/core/src/components/datetime/utils/data.ts
Lines 475 to 505 in 5f12cf8
export const getYearColumnData = ( | |
locale: string, | |
refParts: DatetimeParts, | |
minParts?: DatetimeParts, | |
maxParts?: DatetimeParts, | |
yearValues?: number[] | |
): WheelColumnOption[] => { | |
let processedYears = []; | |
if (yearValues !== undefined) { | |
processedYears = yearValues; | |
if (maxParts?.year !== undefined) { | |
processedYears = processedYears.filter((year) => year <= maxParts.year!); | |
} | |
if (minParts?.year !== undefined) { | |
processedYears = processedYears.filter((year) => year >= minParts.year!); | |
} | |
} else { | |
const { year } = refParts; | |
const maxYear = maxParts?.year ?? year; | |
const minYear = minParts?.year ?? year - 100; | |
for (let i = minYear; i <= maxYear; i++) { | |
processedYears.push(i); | |
} | |
} | |
return processedYears.map((year) => ({ | |
text: getYear(locale, { year, month: refParts.month, day: refParts.day }), | |
value: year, | |
})); | |
}; |
This could just need a new flag that's the fallback in between maxParts?.year
and year
on line 493
Additional Information
No response