Home Forums Front-end Issues javascript maxdate


javascript maxdate

  • Hi,

    I could successfully limit the value of minDate of my datepicker but I cannot set the maxdate args !?!!

    function my_acf_input_admin_footer() {
    //Minimum date is today (0)
    <script type="text/javascript">
    acf.add_filter('date_picker_args', function( args, $field ){
      if($field.attr('data-key') == 'field_582f0a1f11297') { 
        args.minDate = 0;
        args.maxDate =7; 
      return args;
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
  • From the first comment here

    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);

  • Hi John,

    Thank you for your help.
    I’ve tried :

        var maxdate =  new Date(2016,12,9);
        args.maxDate =maxdate ; 

    all days except today and past days are disabled.

    any other idea ?

  • 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.

    Edit: trying 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.

  • This seems to be a bug in ACF setup of the datepicker field. It has been reported to the developer.

  • Hi John,

    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 ?

    Thank you.


  • 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.

  • Hi John,
    ok I understand better. I’m not totally crazy not being able to make this stuff work 🙂

    Would it help to enable WP debugging ?

    What do you think,


  • No, it’s a logic bug, not a bug that will give any type of an error.

  • The developer said that he’ll have this fixed in the next update.

  • fantastic ! The new release fixed the issue !

    It’s working as expected. Fast and Great support! 🙂

    thanks again.

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘javascript maxdate’ is closed to new replies.