Twipped / Kalendae

A javascript date picker that just works.
MIT License
1.99k stars 285 forks source link

restrict years in calendar #231

Open joelyeye opened 4 years ago

joelyeye commented 4 years ago

Is there a way to restrict the calendar to only go back to n amount of years? I am having an issue that when a user enters lets say 10/15/19 it pick 10/15/0019 instead if 10/15/2019.

Thanks

kesalkarsaket commented 11 months ago

@joelyeye you can use react-datepicker library to only go back to restricted amount of years. You can try out using react moment library and u can pass props like min and max dates to restrict the year limit <DatePicker open={dateOpen} minDate={moment().subtract(18, 'years').toDate()} maxDate={moment().toDate()} mode="date" onConfirm={date => { let mm = date.getMonth() + 1; let dd = date.getDate(); const yy = date.getFullYear(); if (dd.toString().length === 1) dd = 0${dd}; if (mm.toString().length === 1) mm = 0${mm}; const selectedDate = ${dd}/${mm}/${yy}; setDateOpen(false); }} onCancel={() => { setDateOpen(false); }} />