Advanced custom fields: Customise date picker’s start date (need to choose year 1500 onwards)

In Advanced custom fields, I would like to customise the date picker so that, ideally, I can only select a year in the 1500s/1600s but at the very least allow the datepicker to go back to the 1500s. At present it only goes to 19 something.

Would anyone know how I’d implement this?

Related posts

1 comment

  1. You can do this by customizing the plugin.

    You’ll want to find timepicker.js in /wp-content/plugins/acf-field-date-time-picker/js/timepicker.js

    And change line 21:

    , yearRange: "-100:+100"
    

    to your preferred range, for example:

    , yearRange: "-500:+100"
    

    This gives you a dropdown that, by default, goes back 500 years and forth 100, from the current year.

    Or you can hardcode a specific range like this, to fit your specific needs:

    , yearRange: "1500:1699"
    

    Of course these will be overridden if the plugin gets updated, but it’s a quick fix to your current issue.

    The whole code-block looks like this by default:

    input.addClass('active').attr("placeholder", (is_timeonly) ? time_format : date_format + ' ' + time_format).datetimepicker({
    changeYear: true
    , yearRange: "-100:+100"
    , changeMonth: true             
    , timeOnly: is_timeonly
    , timeFormat: time_format
    , dateFormat: date_format
    , showWeek: (input.attr('data-show_week_number') != "true") ? 0 : 1
    , ampm: has_ampm
    , controlType: input.attr('data-picker')
    , timeOnlyTitle: input.attr('title')
    , monthNames: timepicker_objectL10n.monthNames
    , monthNamesShort: timepicker_objectL10n.monthNamesShort
    , dayNames: timepicker_objectL10n.dayNames
    , dayNamesShort: timepicker_objectL10n.dayNamesShort
    , dayNamesMin: timepicker_objectL10n.dayNamesMin
    , firstDay: timepicker_objectL10n.firstDay
    });
    

Comments are closed.