I've found a confusing/inaccurate experience with Timestamp field widget when the field is required.
Steps to reproduce
Create a Timestamp field on a content type; set it to be required, with no default value.
When editing, I see:

Expected
According to the help text - I can leave this field blank, and when I save the node, it will populate with the date/time at which I submitted.
Actual
I cannot leave this field blank - the HTML5 'required' attribute enforces populating it before form submit. If I remove that attribute with browser inspector, I can submit, but the form API marks the field with an error because the value was empty. Populating it with the current date/time does not happen, regardless.
Here, what the help text says seems to be incorrect.
Solution?
Enforcing the field to be required, as configured, makes sense. The current date/time default can still happen, when the node/add form is loaded. Perhaps in this case, the wording of the help text should be adjusted.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | drupal-timestamp-widget-use-current-time-2978467.patch | 1.19 KB | AshM |
Comments
Comment #2
mpdonadioNice catch. Can you confirm the field type? I think we are actually talking about Timestamp fields and not the ones provided by the datetime.module. That text appears only in TimestampDatetimeWidget.
I would propose something like this to remain BC.
Comment #4
joachim commentedPatch looks ok but there are no tests, so setting back to NW.
Comment #5
tea.time commented@mpdonadio Hey Matt.
Yep my mistake, this is the Timestamp field type. (I'm not sure which component it belongs under in the issue metadata, though.) I updated the wording to refer to that.
I happened to find #2978727: Use current time setting for the timestamp widget which duplicates the second scenario I described (if the field is not required, the default to time of form submit prevents the ability to save with an empty value). Since your patch addresses the first scenario I described, I've removed the second one in favor of that other issue.
As to your patch, that makes sense - the field is required, thus the user must enter a value. I also like the idea of having a field setting for whether to default to the current time, which is actually what #2978727: Use current time setting for the timestamp widget proposes...
Comment #6
tea.time commented(whoops - reference correct field type in issue title)
Comment #7
scott_euser commentedTests added
Comment #8
scott_euser commentedComment #9
mpdonadioTest changes look good to me. Would like to limit scope to just this bug for the description text, and do the weirdness of being required in #2978727: Use current time setting for the timestamp widget.
Comment #10
mpdonadioOk, very weird quirk that I am seeing. Test looks completely valid, and I stepped through the HTML output. When I test manually via the UI for field creation, I can't get an empty blank value to show up on the node edit page. This is because the field config page uses the actual widget, which sets the default value upon submission for the field settings. o_O
So, I can't reproduce the screenshot in the IS right now. Going through logs as I seem to recall an issue around default values with either timestamp or datetime.
Comment #11
mpdonadioAnd, after bouncing back to #2978727: Use current time setting for the timestamp widget, it looks like these problems are fairly coupled.
Comment #12
tea.time commentedYeeeep, that drives me nuts too... I had a client asking why all their test articles had exactly the same date/time, haha.
It's been awhile since I took that screenshot in the OP but I think what I must have done was manually edit the exported config to set the default value to empty, and then imported that config. Because of the widget as you noted, there's no way to set it as such in the admin UI.
I'm not familiar with writing tests tbh, but since this patch is particularly altering the help text - should the test only need to check the help text according to whether the field is required vs. not required, and not check for empty values in the widget?
Comment #13
sahil432 commentedRelated Issue Updated
https://www.drupal.org/project/drupal/issues/2978727
Comment #18
pcambraAdding another related issue, I think this is not accurate even for non-required fields, I've just tested this and got an error message:
The Timestamp date is invalid. Please enter a date in the format 2020-10-18 17:15:27.Adding a test that shows the case, not extending #7, just a test only patch.
Comment #19
pcambraA better named one.
Comment #20
AshM commentedPatch works on 8.9.13.
It does not have tests.