[Caching] Date field default does not change without clearing the caches

Created on 5 August 2022, almost 3 years ago
Updated 8 April 2024, over 1 year ago

Hello, the date in the field does not change. In the field settings I specify (today ; +1 day). The problem concerns open forms. I disabled the cache on the site, the next day the date was not updated. Only clearing the cache helps.

In modal forms everything works correctly. Dates are updated daily

https://disk.yandex.ru/i/Lct5Dv23Dacehg - settings

https://disk.yandex.ru/i/roKh18hyutFmxQ - open form. Dates must be 05.08.2022; 06.08.2022

https://disk.yandex.ru/i/y0qGP9SLLbHp_Q - modal form

Addition. I also forgot to add, in open forms the date also changes, BUT only when I'm in the admin panel. As soon as I log out of the admin panel, the dates become irrelevant.

🐛 Bug report
Status

Needs work

Version

6.2

Component

Code

Created by

🇷🇺Russia alex malik

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States jrockowitz Brooklyn, NY
  • 🇮🇳India shahin-raza Mumbai

    Any solution for this issue? I am also facing the date caching issue in webform for anonymous users, today's date is showing one day late.

  • 🇺🇸United States jrockowitz Brooklyn, NY

    Your best work-around may be to set the default date using JavaScript.

  • 🇷🇺Russia alex malik

    I tried using Custom JavaScript, it works. The date changed immediately without clearing the cache. Here is my code

    document.addEventListener('DOMContentLoaded', function () {
      // Find date fields by their ID
      var dateField1 = document.getElementById('edit-your-date-field-id-3days'); // For +3 days
      var dateField2 = document.getElementById('edit-your-date-field-id-21days'); // For +21 days
    
      // Get current date
      var today = new Date();
    
      // Set date for +3 days
      today.setDate(today.getDate() + 3);
      dateField1.value = today.toISOString().split('T')[0]; // Format YYYY-MM-DD
    
      // Set date for +21 days
      today.setDate(new Date().getDate() + 21);
      dateField2.value = today.toISOString().split('T')[0]; // Format YYYY-MM-DD
    });

    How to Use:
    1. Replace the Identifiers:

    • Change 'edit-your-date-field-id-3days' and 'edit-your-date-field-id-21days' to the actual IDs of your date fields.

    2. Insert the Code:

    Add this code in the custom JavaScript section of your web form settings.
    /admin/structure/webform/manage/webform-id/settings/assets

    3. Save Changes and verify the results on the form page.

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦
Production build 0.71.5 2024