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
  • Note: Calendar can be set to "Today" on Chrome.
    Calendar - can set to today

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

    Proposed resolution

    Note this is what the UX committee agreed to if we want this feature.

    • 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.

    Remaining tasks

    • 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

    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".

    • 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


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

Comments

wtchan created an issue. See original summary.

wtchan’s picture

StatusFileSize
new53.17 KB
poornima.n’s picture

StatusFileSize
new2.23 KB

You need to keep both the date and time field blank to use the time and date of form submission. I have updated the instruction

lomasr’s picture

Assigned: Unassigned » lomasr
Status: Active » Needs review
moonpeak’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new9.01 KB

Hi,

I have checked the edit node page (of an Article). Instruction for date and time has been updated. PFA screenshot for the same.

lomasr’s picture

#3 patch works

lomasr’s picture

Status: Reviewed & tested by the community » Needs review
lomasr’s picture

Assigned: lomasr » Unassigned
wtchan’s picture

Hi,

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.

Version: 8.1.7 » 8.1.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.1.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

We 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.

larowlan’s picture

Version: 8.9.x-dev » 9.3.x-dev
Status: Needs review » Needs work

Since #2508866: Field description is not displayed with Timestamp datetime widget this can be configured per base-field.

So the patch needs to modify the setDescription call in this hunk in core/modules/node/src/Entity/Node.php

$fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('The time that the node was created.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'timestamp',
        'weight' => 0,
      ])
      ->setDisplayOptions('form', [
        'type' => 'datetime_timestamp',
        'weight' => 10,
      ])
      ->setDisplayConfigurable('form', TRUE);
worldlinemine’s picture

This 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.

larowlan credited quietone.

larowlan’s picture

Title: Node edit prompts invalid date for blank time in authoring information » Add a 'use current date and time' checkbox to the date time widget and deprecate the 'empty = current date time' functionality
Version: 9.3.x-dev » 9.4.x-dev
Component: node system » datetime.module
Category: Bug report » Feature request
Issue tags: -Needs usability review +DrupalSouth

Thanks

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

benjifisher’s picture

As 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jaime@gingerrobot.com’s picture

Assigned: Unassigned » jaime@gingerrobot.com
jaime@gingerrobot.com’s picture

jaime@gingerrobot.com’s picture

Issue tags: +Usability
jaime@gingerrobot.com’s picture

Issue tags: +behaviors
jaime@gingerrobot.com’s picture

Issue tags: +widget
jaime@gingerrobot.com’s picture

Issue summary: View changes
StatusFileSize
new49.53 KB
new54.5 KB
jaime@gingerrobot.com’s picture

Assigned: jaime@gingerrobot.com » Unassigned
Issue summary: View changes

Updating 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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.