Topic: Datepicker, max date of TODAY and go back 100 years FROM today
luthersites pro asked 5 years ago
Expected behavior That setting "max: true" would make today the highest day (whether there's already a date in the field or not) That setting "selectYears: 100" would offer 100 years previous to today
Actual behavior "max: true" sets the day as whatever date is in the field already as the last day, and then creates dates 100 years before that, and I end up not having all sorts of years.
Resources (screenshots, code snippets etc.) I'm trying to create a "select your date of birth" field, which needs more than the default 20 years, doesn't need a date greater than today, and, should there already be a date in the field or just zeros, will use today as the standard for counting back 100 years. Either I am using the javascript wrongly, or it doesn't seem to be doing this basic function. I do wish that the default function, .pickdate() without any options, was set to list years of more than 20. Some of us are older than 20 :-)
Mateusz Łubianka staff answered 5 years ago
Hi @luthersites,
Try to use this code:
$('.datepicker').pickadate({
format: 'dd/mm/yyyy',
selectMonths: true,
selectYears: 100,
max: true
});
Best,
luthersites pro answered 5 years ago
Actually, what I'm using is
format: 'mmm dd, yyyy', selectMonths: true, selectYears: 100, max: true, formatSubmit: 'yyyy-mm-dd', closeOnSelect: false
There's a "date" in the field, from the database, that is 0000-00-00. So the latest year I see is 1889. If I set the date to dec 31, 1889, close the datepicker, than reopen, it then allows me to go to 1949. Also, the formatSubmit isn't formatting the date for mySql. Not a huge deal, but when I save the field (ajax), it submits it as mmm dd, yyyy. This I can fix server-side, but isn't formatSubmit supposed to do that?
Mateusz Łubianka staff commented 5 years ago
You could use the pre-fill value option using 'data-value="[2015,6,1]"'. It seems to works well. It seems that it could be an little issue with formatSubmit so I'll create the task to check it. Thank you very much for report it.
Best,
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.12.0
- Device: PC
- Browser: Firefox
- OS: Windows 10
- Provided sample code: No
- Provided link: No