• Resolved itsViney

    (@itsviney)


    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 Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @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

    (@wpmudev-support2)

    Hello @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

    (@itsviney)

    Thanks Adam. The ACF fields are on an 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 Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @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

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