I want to be able to restrict the date field to only allow someone to select a date 7 days in the future or beyond? Any thoughts on if this is possible?
Thanks,
Lisa
I want to be able to restrict the date field to only allow someone to select a date 7 days in the future or beyond? Any thoughts on if this is possible?
Thanks,
Lisa
Add a custom class to your date field, something like "futureDateOnly" then the following code will adjust the minimum date attribute that is used by the date picker.
$(document).ready(function(){ // Get date var d = new Date(); // Add 7 days (+ 1 to month is necessary because it uses a 0 index) var dmy = [d.getDate() + 7, d.getMonth() + 1, d.getFullYear()]; // Format date for (var n = 0; n < 2; n++){ if (dmy[n].toString().length < 2){ dmy[n] = "0" + dmy[n]; } } // Set the min date value for the date calendar $('.futureDateOnly input').attr('min',(dmy[2] + "-" + dmy[1] + "-" + dmy[0])); });
That was perfect. Thanks so much!
This code was working when I tried it last week but now I'm getting the following error message. I believe it is because its July 30th and this is missing something to recognize the new month instead of just adding 7 days to today's date? It also won't allow the calendar to even pop up? Anybody have any idea on how to fix this?
Thanks,
Lisa
Try this instead. Turns out you need to add 7 days a different way to make sure it automatically moves over to the next month.
$(document).ready(function(){ // Get date var d = new Date(); // Add 7 days to date d.setDate(d.getDate() + 7); // + 1 to month is necessary because it uses a 0 index var dmy = [d.getDate(), d.getMonth() + 1, d.getFullYear()]; // Format date for (var n = 0; n < 2; n++){ if (dmy[n].toString().length < 2){ dmy[n] = "0" + dmy[n]; } } // Set the min date value for the date calendar $('.futureDateOnly input').attr('min',(dmy[2] + "-" + dmy[1] + "-" + dmy[0])); });
Thank you, that seems to have corrected the issue!