First update after 20 december 2024 needs extra attention!

Conditional Fields 2.5.5 and later use new folder and file names.
As a result, the plugin will deactivated automatically the first time that you update from version 2.5.4.
Please make sure to activate the plugin manually after the update.

Read more

Date range

At this point the Conditional Fields plugin is unaware of date ranges, but this is a problem that can be solved with custom functions. Custom functions are available in Conditional Fields Pro. Check out the example below.

Example 1

Form

    Enter a date between 29-Aug-2019 and 7-Sept-2019:

    Well done!

    Form Code

    [group nope]Enter a date between 29-Aug-2019 and 7-Sept-2019:[/group]
    [date date]
    [group well-done]Well done![/group]
    <script>
      fromdate = new Date("2019-08-29");
      untildate = new Date("2019-09-07");
      function date_between(field) {
        // The next line is needed for future compatibility:
        field = field instanceof HTMLElement ? field : field[0] || field;
        const checkdate = field.valueAsDate;
        if (!checkdate) {
          return false;
        }
        if (checkdate >= fromdate && checkdate <= untildate) {
          return true; // date is between the from and until date
        } else {
          return false; // date is not between the from and until date
        }
      }
      function not_date_between(field) {
        return !date_between(field);
      }
    </script>

    Conditional Fields (Text)

    show [well-done] if [date] function "date_between"
    show [nope] if [date] function "not_date_between"

    Edit this form in the form tester

    Example 2 – Multiple date ranges

    Form

      Enter a date in January 2020 or in March 2020

      Well done!

      Form Code

      [group nope]Enter a date in January 2020 or in March 2020[/group]
      [date date]
      [group well-done]Well done![/group]
      <script>
        const validDates = [
          [new Date("2020-01-01"), new Date("2020-01-31")],
          [new Date("2020-03-01"), new Date("2020-03-31")],
        ];
        function date_between(field) {
          // The next line is needed for future compatibility:
          field = field instanceof HTMLElement ? field : field[0] || field;
          const checkdate = field.valueAsDate;
          if (!checkdate) {
            return false;
          }
          for (let i = 0; i < validDates.length; i++) {
            const fromdate = validDates[i][0];
            const untildate = validDates[i][1];
            if (checkdate >= fromdate && checkdate <= untildate) {
              return true; // date is between the from and until date
            }
          }
          return false; // date is not between the from and until date
        }
        function not_date_between(field) {
          return !date_between(field);
        }
      </script>

      Conditional Fields (Text)

      show [well-done] if [date] function "date_between"
      show [nope] if [date] function "not_date_between"

      Edit this form in the form tester