Problem/Motivation
Motivation
To improve the UX of the datetime fields.
Problem/s
- There should be an easy way to set the field value to the current date & time
Steps to reproduce
- As Administrator
- Add a Date field to the Article content type
- Set the field to Not Required
- Click on Content
- Click on "+ Add content
- Click on "Article"
- Set a date in the past date and a time in the past on the new datetime field
- Now try and adjust the field to show the current time easily
- Add a check box to the date time field with the label "use current date and time".
- When the checkbox is tickets, the date/time field is set to the current date and time.
- Decide if we want this feature just for the time field on Chrome. Are there other examples where this is a problem? Anyone want to comment here if it's an issue for you?
- Write the patch for the above
- As an admin user that can edit content
- Visit the node add form
- Open the authoring information sidebar
- Remove the value from the time field
- Submit the form
- Note the error about invalid date
Note: Calendar can be set to "Today" on Chrome.

On Chrome there is no "now" button on the widget.

Proposed resolution
Note this is what the UX committee agreed to if we want this feature.
Remaining tasks
User interface changes
As per above
API changes
N/A
Data model changes
N/A
Release notes snippet
Added an optional checkbox to the datetime widget to allow the current date and time to be set by the content modifier.
Original report
When a user that edit content is editing a date time fields value with a datetime widget the help text used to say 'leave blank to use the time of submission'. This could be misinterpreted such that a user empties the time, but not the date. This then results in an error "The Authored on date is invalid. Please enter a date in the format yyyy-mm-dd hh:mm:ss".

When a datetime field is set to not required and the value in the widget is blank, the field should save as empty
Before

After

| Comment | File | Size | Author |
|---|---|---|---|
| #26 | Screenshot 2022-10-23 145250.jpg | 54.5 KB | jaime@gingerrobot.com |
| #26 | Screenshot 2022-10-23 144854.jpg | 49.53 KB | jaime@gingerrobot.com |
| #5 | Authoring information screenshot.png | 9.01 KB | moonpeak |
| #3 | 2779185-1.patch | 2.23 KB | poornima.n |
| #2 | Screenshot from 2016-08-05 00:20:42.png | 53.17 KB | wtchan |
Comments
Comment #2
wtchan commentedComment #3
poornima.n commentedYou need to keep both the date and time field blank to use the time and date of form submission. I have updated the instruction
Comment #4
lomasr commentedComment #5
moonpeak commentedHi,
I have checked the edit node page (of an Article). Instruction for date and time has been updated. PFA screenshot for the same.
Comment #6
lomasr commented#3 patch works
Comment #7
lomasr commentedComment #8
lomasr commentedComment #9
wtchan commentedHi,
The patch works with both blank fields being defaulted to the current date and time. But, according to the configuration of the scheduler, it states the following:
"Allow users to enter only a date and provide a default time.
When only a date is entered the time will default to a specified value, but the user can change this if required.
Default time
(to be configured by the user)
This is the time that will be used if the user does not enter a value. Format: HH:MM:SS."
I assume that I can input a date only and leave the time blank but actually I can't.
Comment #12
larowlanWe triaged this issue as part of DrupalSouth 2021 code sprint.
We considered whether making it a feature request so that you could ignore just the time part and have it use the current time.
However we concluded that this would make changes to the DateTime element and impact anywhere a date field was used so thought perhaps it was best to continue with the UI text improvement.
There was some debate about the best wording so we decided to refer this issue to the UX team for review.
We'll ping them about it in slack.
Thanks for taking the time to submit a bug report.
Comment #13
larowlanSince #2508866: Field description is not displayed with Timestamp datetime widget this can be configured per base-field.
So the patch needs to modify the
setDescriptioncall in this hunk incore/modules/node/src/Entity/Node.phpComment #14
worldlinemine commentedThis issue was discussed today at the Drupal Community UX meeting. We noted that the latest release of Drupal 9.3.0-alpha1 the wording has changed to no longer reference the feature behavior regarding using current date and time upon blanking the date and time fields. Additionally, it was noted that these fields are only editable by default by those with administrative permissions. For this reason it was agreed upon that our recommendation is to close this issue as "Outdated".
If the goal of this issue is to improve the behavior of the field we recommend making the "use current date and time" functionality deliberate rather than as a result of blanking the two fields. For instance, adding a checkbox (which by default be unchecked) that allows the user to chose the behavior of "use current date and time".
Thank you so much for your work on this issue.
Comment #17
larowlanThanks
I think that making it a deliberate feature sounds great.
On that basis moving this to a feature request.
Crediting @quietone and @deciphered who actively triaged this with me at DrupalSouth
Comment #18
benjifisherAs mentioned in #14, we discussed this issue at #3249152: Drupal Usability Meeting 2021-11-12. That issue has a link to a recording of the meeting.
I see that #17 updated the issue title, but the "Proposed resolution" section in the issue summary also needs an update. I am adding the issue tag for that.
Comment #21
jaime@gingerrobot.com commentedComment #22
jaime@gingerrobot.com commentedComment #23
jaime@gingerrobot.com commentedComment #24
jaime@gingerrobot.com commentedComment #25
jaime@gingerrobot.com commentedComment #26
jaime@gingerrobot.com commentedComment #27
jaime@gingerrobot.com commentedUpdating the description using information in the comments.
Please note here if you want this code written still as it's moved a lot from the original requirement and may no longer be necessary. We can assess again 6 months if anyone has replied?.
Maybe more browsers will implement "Now" and "Clear" buttons for the elements in the mean time. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time