Datetime element formats are confusing

Created on 3 May 2017, over 7 years ago
Updated 27 October 2023, about 1 year ago

Problem/Motivation

A number of users have become confused around the datetime element's format attributes #date_date_format and #date_time_format.

If you use the HTML5 form elements (which are only supported in some browsers, others make them behave like text fields), then the date/time formats *have* to be the HTML5 flavors ('Y-m-d' and 'H:i:s'). And per Datetime::getInfo(), they default to the HTML5 inputs when not specified.

Part of the problem comes from the docs being in a weird place for this form element.

Proposed resolution

Possible solutions include:

  1. Improve the docblocks and/or move some of the information around, perhaps much on Datetime::processDatetime() should be moved to the top level comment on the class (and some of that may not be accurate in Drupal 8 anymore).
  2. Trigger a notice when custom formats are specified with the HTML5 elements.
  3. If a custom format is specified, then force the element to 'text' (maintainer is not keen on this, and it has probably has BC consequences).

Remaining tasks

Discuss, agree, code.

User interface changes

None

API changes

TBD

Data model changes

None.

Original Summary

We are getting error - Error : "The date is invalid. Please enter a date in the format 2017-05-03 12:57:23". even if we provided expected format in '#date_date_format' & '#date_time_format' in our custom form field - datetime as below code.

$form['datetime'] = [
  '#type' => 'datetime',
  '#size' => 20,
  '#date_date_format' => 'd/m/Y',
  '#date_time_format' => 'H:m',
];

Value Provided on Form Submission : "03/05/2017 12:57:23"

Expected format : "d/m/Y" but Drupal 8 - DateTime supports only "Y-m-d".

I guess, Drupal 8 follow the HTML5 () default date format. Please skip this validation if user provided their own date formats. Please help us to resolve this.

--
Thanks
Vignesh.R

📌 Task
Status

Active

Version

11.0 🔥

Component
Datetime 

Last updated 2 days ago

Created by

🇮🇳India vickey

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

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.

Production build 0.71.5 2024