Title: Dynamically disable/enable datepicker dates
Last modified: April 28, 2023

---

# Dynamically disable/enable datepicker dates

 *  Resolved [itsViney](https://wordpress.org/support/users/itsviney/)
 * (@itsviney)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/)
 * I’m setting up a site with an ACF options page the client can use to set their
   business opening and closing dates and also enter planned closures in advance,
   since they change regularly.
 * It’s really handy that Forminator’s datepicker field lets you specify dates or
   date ranges to exclude from the popup calendar, but is there a hook or any other
   method available to set these dynamically? I’d like to pull in the date ranges
   from the ACF options page so the user doesn’t have to key them in twice and keep
   them in sync.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/#post-16695313)
 * Hi [@itsviney](https://wordpress.org/support/users/itsviney/)
 * I hope you’re well today and thank you for your question!
 * Currently it isn’t possible out of the box. There may be a workaround doable,
   using custom code snippet, but we’ll need to consult that with our developers
   and before doing that, let me make sure that we are on the same side:
 * I understand that there’ll be set of dates defined in ACF fields but:
 * – are those a “user fields” (as in “additional user meta”) so they should be 
   recognized by logged-in user ID (when form is rendered) or by some post ID (if
   yes – where it should be taken from; e.g. post that form is embedded on)?
 * – the dates – should those be used as “Start/End” dates for datepicker limits
   settings or the “Disabled dates” (those are specific dates) or “Disabled date
   ranges”?
 * Let us know and we’ll take it to our developers to see if there’d be some custom
   code possible for it.
 * Best regards,
    Adam
 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/#post-16712022)
 * Hello [@itsviney](https://wordpress.org/support/users/itsviney/) ,
 * We haven’t heard from you for several days now, so it looks like you don’t have
   more questions for us.
 * Feel free to re-open this ticket if needed.
 * Kind regards
    Kasia
 *  Thread Starter [itsViney](https://wordpress.org/support/users/itsviney/)
 * (@itsviney)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/#post-16712324)
 * Thanks Adam. The ACF fields are on an [options page](https://www.advancedcustomfields.com/resources/options-page/)
   so they’re effectively globals, not linked to a specific page or user.
 * I have it set up with a start and end date inside a repeater field so the user
   can enter as many closure periods as they need. ACF returns this as a nested 
   array. If one of your Devs was able to provide an example of how this could be
   done I’d really appreciate it. No need to worry about specifics like the field
   names – I’m hoping I can get the gist and whatever snippit they provide.
 * Thanks 👍
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/#post-16719323)
 * Hi [@itsviney](https://wordpress.org/support/users/itsviney/)
 * Thanks for response!
 * So it is doable 🙂 I gave it a go and came up with this code:
 * [https://gist.github.com/adczk/e72fc7d55de43978152ff32757ad59b1](https://gist.github.com/adczk/e72fc7d55de43978152ff32757ad59b1)
 * It should be added to the site as MU plugin and there are two requirements:
 * 1. in this line
 * `$allowed_fields = array( 'date-1' );`
 * you need to define IDs of datepicker fields which should be affected; since it’s
   an array, you simply separate them with commas if there’s more than one; note:
   it’s not aware of the form ID
 * 2. you must make sure that the format of date set in datepicker field in Forminator
   and set as “return format” in ACF date-type field are the same formats.
 * Also, you need to adjust your field names:
 * a) main repeater name in theses lines
 *     ```
       if( have_rows('date_ranges', 'option') ) {
       		while ( have_rows('date_ranges', 'option') ) { 
       ```
   
 * b) and start/end date subfields’ names in this line
 * `$date_ranges[] = get_sub_field('start_date') . ' - ' . get_sub_field('end_date');`
 * I tested this code and it works fine on my end:
 * [⌊2023-05-08_12-32-34⌉⌊2023-05-08_12-32-34⌉[
 * [⌊2023-05-08_12-33-01⌉⌊2023-05-08_12-33-01⌉[
 * Best regards,
    Adam

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Dynamically disable/enable datepicker dates’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-disable-enable-datepicker-dates/#post-16719323)
 * Status: resolved