I'm having a strange problem with a date field on a webform.
I have it set, in the Element Settings, to a minimum date of "today" and a maximum date of +2 months. To my understanding, this should allow the viewer to select any date from the day they are submitting the form to two months later. Under Form Validation, nothing is checked — so to my understanding, it should not be performing any sort of validation.
But — when I test the form, no matter what value I set for the date, I get "The value in What would be the most convenient time to meet with our expert?: Date has to be greater than Thu, 12/17/2020 - 00:00." Even though the value IS greater than that. Even dates weeks in the future result in the same message.
I initially got a similar error for the time field that follows it, but that one disappeared when I switched the element from jQuery time picker to HTML5 time input. (I had initially used the jQuery time picker for both, but switched it to HTML5 because the jQuery picker was giving me other weird problems). But switching to HTML5 did not affect the validation issue with the date field.
So there seem to be two issues here: First, since I didn't set any rules under Form Validation, why is it trying to validate input anyway? The only date min/max I set was under Element Settings, which as far as I know should only affect what's displayed to the viewer.
Second, why is the unwanted validation insisting that the date has to be greater than today when the date IS greater than today?
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 3188940-31.patch | 9.54 KB | jrockowitz |
| #27 | 3188940-27.patch | 1.9 KB | jrockowitz |
| #22 | 3188940-22.patch | 1.89 KB | jrockowitz |
| #17 | Screen Shot 2021-01-15 at 2.10.48 PM.png | 75.56 KB | safetypin |
| #16 | Screen Shot 2021-01-15 at 2.10.49 PM.png | 436.48 KB | alberto56 |
Comments
Comment #2
spidersilk commentedComment #3
jrockowitz commentedI am not able to replicate this issue using the attached webform in Chrome.
The submitted value must be YYYY-MM-DD.
Please provide an example webform.
Comment #4
safetypinI just received a report from someone else that this was happening for our webform. I went to test it, and everything worked fine. Sounds like we're in almost exactly the same error situation, tho. We have 2 date fields, we are validating "required" and the date selection is from "today" to "+1 year" for one field and "+2 year" for the other.
Comment #5
jrockowitz commentedMy best guess is a specific browser is having an issue with date min/max. This could also be triggered by a time zone related issue.
Someone needs to provide the steps and browser required to replicate this issue.
Comment #6
safetypinIt is something to do with the browser, but it's not super specific. Both Chrome and Firefox are unable to submit the form. Safari can do it. What's confusing is that in both Chrome and Firefox the form is submitted to the server and the error I'm seeing is a drupal message, not a browser/javascript validation error message. I will try to recreate the error on a new form.
Comment #7
safetypinI have narrowed my problem down to the date_format configuration. Custom properties like this cause the error:
If I leave the formatting like this, the error goes away:
I duplicated the form and still saw the problem. I deleted the forms, and then added to new fields for the date fields, and the problem went away. When I exported and compared the two forms, I see this as the difference:
These are missing in the new form that doesn't have the error. When I added the
date_date_formatconfiguration, the problem came back, so I think the problem is related to date format requirement. I'm not sure about the'#format_items': comma. I can't find a place for that configuration in the original form, so I don't know where to put it in the new form to test whether it has any effect.Comment #8
dennis cohn commentedI can confirm this issue.
All our forms with date elements doesn't validate anymore!
Only new forms with date fields are validating correctly.
Our date format is
d-m-Y(in advanced custom settings) and we don't have any min/max set.We're editing all (!) our forms now with the date format
Y-m-dso the forms are working again.But this is a quick fix for us and isn't the ideal solution as the date format is now different then our standard date format on our website.
Comment #9
dennis cohn commentedSee attachment for the error
Comment #10
jdearie commentedI can confirm this issue as well. Not all of our forms have the date format of
d-m-Y. I'm not sure why one form hadd-m-Y, whereas a new form as well as several older forms were usingY-m-dwhen the validation and other settings were identical.Changing the setting from
d-m-YtoY-m-dsolved the problem.Comment #11
jrockowitz commentedComment #12
jrockowitz commentedI am not able to replicate this issue using the attached webform with the below elemense
Comment #13
jrockowitz commentedPlease provide an example element that can be used to replicate the issue.
My local site is in English using Drupal's default locale and regional settings.
Comment #14
dennis cohn commented@jrockowitz,
I've exported a webform that gives the error:
Comment #15
dennis cohn commentedComment #16
alberto56 commentedI believe "active" is more appropriate than "needs work" (which I think means that a solution is being worked on).
I am getting this problem with the following form:
Even though I have specified m/d/Y as the date format, the date format appears as Y-m-d on Firefox, Chrome, Opera on mac OS Big Sur 11.1,
The problem does not happen on Safari on mac OS Big Sur 11.1, IE 11 on Windows 8.1, Firefox on Windows 10
Please see the enclosed image
Comment #17
safetypin@jrockowitz - I created a completely new form using the source you provided on a development server and replicated the error. I've attached a screenshot - I clicked into each of these forms and selected a new date in the date picker, and the date is formatted incorrectly. I'm not sure it's relevant but I'm using Firefox on MacOS. I can confirm that Safari won't replicate the error.
Comment #18
alberto56 commentedA workaround we've used on production forms is to change the forms from "date" type to "textfield".
Also, I am experiencing this on 6.x, I have not tested it on 5.x.
Comment #19
alberto56 commentedAccording to https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-..., major bugs "Interfere with normal site visitors' use of the site (for example, content in the wrong language, or validation errors for regular form submissions), even if there is a workaround."
Based on the above I'll set this to major.
Comment #20
alberto56 commentedI will set the version to 6.0.0 because that is the version I tested. However it might be safe to say that the issue might have been introduced in 5.23 which was released on the same day as 6.0.0. (I tested 5.22 -- see below -- and it works fine).
Here is how I reproduced this. I will start by demonstrating that version 5.22 works perfectly; then we will show that 6.0.0 (presumably 5.23 also, but someone should confirm this) fails.
Go to /form/test and enter today's date in the format m/d/Y (at the time of this writing that's 01/15/2021), then submit. Try it with several different browsers.
Up to now everything works fine.
Again, go to /form/test and enter today's date in the format m/d/Y (at the time of this writing that's 01/15/2021), then submit. Try it with several different browsers.
Methodology
I created a brand new Drupal site on a Docker machine using d8 starterkit, then used my local mac OS machine (11.1) to test mac OS and lambdatest to test Windows.
My only workaround for now is to remove all date fields and replace them with plain text fields.
Comment #21
jrockowitz commentedI think the issue is with Webform 6.0, you currently need to have the jquery_ui_datepicker.module enabled.
Do you have the jquery_ui_datepicker.module enabled? If yes, does the issue still occur?
Comment #22
jrockowitz commentedI think the attached patch starts to address this issue.
Comment #23
dennis cohn commentedI can confirm that after I've enabled the jQuery UI Datepicker module, the issue is gone.
Comment #24
jrockowitz commentedThe patch should help address the issue for the below scenarios.
In Drupal 8, core's or the jquery_ui_datepicker.module can be used.
In Drupal 9, the jquey_ui_datepicker.module is an optional dependency. If the jquey_ui_datepicker.module is not installed the #date_date_format will be ignored.
Comment #25
jrockowitz commentedComment #26
alberto56 commentedThe patch inserts the
$thisoutside of an object, in the webform_library_info_alter() function, in the file ./includes/webform.libraries.inc, which results in the error:Error: Using $this when not in object context in webform_library_info_alter() (line 72 of modules/contrib/webform/includes/webform.libraries.inc).Also, without the patch, On Drupal 8 with Webform 6.0.0, I ran
After that, with the form from comment 20, the following browsers worked as expected (d8/wf6/jquery_ui_datepicker 8.x-1.0):
* Safari mac OK
* FF mac OK
* Chrome mac OK
* IE11 win8.1 OK
* FF win10 OK
* Chrome win10 OK
I then ran a fresh install of WF6 on D9, and had the same errors as described in comment 20. Again, I did not add the patch because of the "this when not in object context" error.
I then ran this on my D9 setup:
After that, with the form from comment 20, the following browsers worked as expected (d9/wf6/jquery_ui_datepicker 8.x-1.0):
* Safari mac OK
* FF mac OK
* Chrome mac OK
* IE11 win8.1 OK
* FF win10 OK
* Chrome win10 OK
Thus, using jquery_ui_datepicker works perfectly.
Setting to "needs work" because of the "this when not in object context" error introduced by the patch.
Comment #27
jrockowitz commentedComment #28
alberto56 commentedThanks for the patch! I ran the following tests with patch at 27, using the latest dev version (2ec980b00dff2f2f0a5ba35c4940817405772301) Webform 6.x with the following form:
Without jquery_ui_datepicker, Safari (Mac), FF (Mac), Chrome (Mac) and IE11 (Win10) on Drupal 9, even with the patch, require input in the format YYYY-MM-DD, even though the date format is specified as "m/d/Y" in the form YML.
On FF (Mac), Chrome (Mac) and IE11 (Win10), this is mitigated by the fact that there is a datepicker and it works correctly.
However, on Safari there is no datepicker and no indication that the date needs to be Y-M-D.
I am setting this to needs work based on the following scenario:
One possible solution would be to have a big warning on forms which have date fields on sites (maybe only D9 sites?) without jquery_ui_datepicker, stating something like "date fields might not work as expected without the jquery_ui_datepicker module", and perhaps have hook_requirements() give an error as well, that way site builders migrating from D8 to D9 will not run into this
Comment #29
jrockowitz commentedIn Drupal 9, if the datepicker is unavailable we should completely hide the date format property.
Safari does not support HTML5 datepicker and this is also an issue with date inputs in Drupal core. The best we can do for Drupal 9 is recommend that people install the jquery_ui_datepicker module.
@see #3027747: Safari does not support HTML5 date format so is not clear what format the date needs to be
Comment #30
alberto56 commentedThanks for the info. Based on the above I'll set this to RTBC.
Comment #31
jrockowitz commentedThis patch hides date picker related properties in D9 when the jquery_ui_datepicker is NOT installed.
Comment #32
alberto56 commentedHi, I ran the patch from #31 with the form in #28 on Drupal 8 and 9 with the latest HEAD of Webform 6 (919532f5ceee62b42a01277407ff5c4e6b642cdc at the time of this writing). The results are indentical to the table in comment 28.
Specically, the issues remain with Safari, Chrome and FF on mac OS, and on IE on Windows 11 on Drupal 9 when jquery_ui_datepicker is _not_ enabled.
In #31, you say:
> This patch hides date picker related properties in D9 when the jquery_ui_datepicker is NOT installed.
I cannot find anything different in the patch in 31 and the patch in 27, in terms of functionality. How could I confirm that the patch, in fact, hides date picker related properties in D9 when the jquery_ui_datepicker is NOT installed?
I'll leave at needs review for now.
Comment #34
jrockowitz commented