I could successfully limit the value of minDate of my datepicker but I cannot set the maxdate args !?!!
From the first comment here http://stackoverflow.com/questions/17647162/maxdate-option-in-datepicker
maxDate string must be in the format defined by the dateFormat option. Check your dateFormat option or use date object instead:
var maximumDate = new Date(2013,7,15);
To be honest, I don’t know much about the date field.
I just did some testing and setting minDate to anything <= 0 (without setting maxDate) disables everything before today. Setting anything for maxDate >= 0 without setting minDate disables everything after today.
But setting a minDate using a + value like +10 and not setting a maxDate works as expected, setting a maxDate with a – value like -10 without setting minDate works as expected.
args.minDate = 'November 1, 2016'; sets the minimum date in the datepicker to June 11, 2022, but that format used is the format set in dateFormat.
Thank you very much for your time and help, much appreciated.
var maxdate = ’12/12/2016′;
args.maxDate =maxdate ;
does not work neither….
As you can imagine, this function is very important for me. Can I imagine any workaround or overrinding until this bug is fixed ?
The problem is something that the developer is going to need to fix, but I can summarize what is happening and maybe that can help you figure out a way around the problem.
The problem is caused by a difference in the display format vs the storage format. ACF always stores dates as yymmdd.
When ACF sets up the date picker field it initially sets it up using the storage format for the date for the display format and then it changes it back to your display format. This switching in the display format is what is causing the min and max dates to go awry. This happens even if the storage format and the display format are the same. Something about changing the display format after you’ve set the min and max dates screws up both of these values. I actually suspect that it has something to do with the jQuery datepicker and how it recalculates the dates rather than something in ACF. (you’d need to try it on a field not controlled by ACF to know for sure)
Unfortunately, altering how ACF initializes the datepicker field causes and error in the way that the date is saved in the database, so there is no quick fix for this in ACF.
The only idea that I can come up with would be to add an onFocus action to the date field and set the min and max dates then instead of by setting the values when ACF is setting up the field. Honestly I don’t even know if that will work, or even how to go about doing it.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.