The documentation for the date form element mentions that the default value should be passed as an array but this is not correct, it should instead be passed as a string in the format 'YYYY-MM-DD', which is ISO-8601 extended.

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review
StatusFileSize
new863 bytes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

ejk’s picture

What needs to be done to get this fixed in the Documentation? Lost an hour to this today, and would like to keep others from the same. Never contributed before but am glad to help any way I can.

girish-jerk’s picture

Patch #2.
Looks fine............!

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

The docs here are indeed wrong.

#5, #6 also both agree on that on.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think this is a bit more complex. The format of the date is not always Y-m-d it is whatever you've set #date_date_format too. I think we should adapt the following documentation from Datetime:

   *   - #date_date_format: A date format string that describes the format that
   *     should be displayed to the end user for the date. When using HTML5
   *     elements the format MUST use the appropriate HTML5 format for that
   *     element, no other format will work. See the format_date() function for a
   *     list of the possible formats and HTML5 standards for the HTML5
   *     requirements. Defaults to the right HTML5 format for the chosen element
   *     if a HTML5 element is used, otherwise defaults to
   *     DateFormat::load('html_date')->getPattern().

and document #date_date_format and the relationship between #default_value and #date_date_format.

pfrenssen’s picture

Issue tags: +Novice

Thanks all for the sudden flurry of activity!

@ejk, if you are looking to make a first contribution, maybe you can try updating the documentation in this patch according to @alexpott's suggestions?

I can help you if you have any questions about how to do this. If you need some information to get you started on rolling a patch, you can start with reading Contribute a patch.

ada hernandez’s picture

Status: Needs work » Needs review
StatusFileSize
new1.31 KB
new1.06 KB

documentation modified like @alexpott suggested

pfrenssen’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/Date.php
@@ -9,15 +9,21 @@
+ * - #date_date_format: A date format string that describes the format that
+ *   should be displayed to the end user for the date. When using HTML5
+ *   elements the format MUST use the appropriate HTML5 format for that
+ *   element, no other format will work. See the format_date() function for a
+ *   list of the possible formats and HTML5 standards for the HTML5
+ *   requirements. Defaults to the right HTML5 format for the chosen element
+ *   if a HTML5 element is used, otherwise defaults to
+ *   DateFormat::load('html_date')->getPattern().

There are a few things here that are not correct:

  1. The property name should remain #default_value. There is no #date_date_format property on this form element.
  2. The user should not pass a date format string but a date in string format, there is a big difference between these two things, the first looks like "2018-03-21" while the second looks like "Y-m-d".

It looks like the documentation from the date format string has been copied, but that's not the intention. Instead we need to describe that the value passed is adhering to this format.

ada hernandez’s picture

@pfrenssen Ok, I understood, I have a second attempt, tell me what do you think:

 * Properties:
 * - #default_value: The date in ISO-8601 extended from date format string
 *   based in #date_date_format property.
robpowell’s picture

@Adita, it looks like you forget your second attempt patch.

prithvi1972’s picture

StatusFileSize
new1.08 KB

Made some changes adhering to #11.

prithvi1972’s picture

Changed comments according to #11 in #14

rakesh.gectcr’s picture

Issue tags: +Nwdug_may18
wim leers’s picture

There was a recent blog post about this: https://blog.purdy.info/2018/07/drupal-8-date-form-field.html (found it via The Weekly Drop 🙏). Let's get this done!

Comments #14 and #15 were unpublished automatically because @prithvi1972 was a very new d.o user. Sorry about that, @prithvi1972!

That being said, the #14 patch did what #12 suggested, and that is still mentioning #date_date_format. That is irrelevant here AFAICT. So this patch still needs work, because the docs AFAICT still don't entirely make sense.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

eclipsegc’s picture

So, reading through this issue, it seems that #date_date_format certainly does impact the #default_value. That being said, it seems like a longer and more contentious issue than should block what are CLEARLY incorrect docs. Can we consider something more along the lines of #2 but with a SLIGHTLY more nuanced description that doesn't mention ISO-8601 since that's clearly only correct sometimes? We could file a follow up to more correctly describe the #date_date_format and not blocks this issue further.

Just a thought,

Eclipse

volkswagenchick’s picture

Issue tags: +drupalnorth2019

Tagging for DrupalNorth 2019

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

nitesh624’s picture

Assigned: Unassigned » nitesh624
nitesh624’s picture

nitesh624’s picture

Status: Needs work » Needs review
atul4drupal’s picture

This issue seems duplicate of https://www.drupal.org/project/drupal/issues/2944552 where it has been addressed.

Also the #date_date_format related issue is been handled as a separate issue @ https://www.drupal.org/project/drupal/issues/2836530

#default_value : https://www.drupal.org/project/drupal/issues/2944552
#date_date_format : https://www.drupal.org/project/drupal/issues/2836530

idebr’s picture

Status: Needs review » Closed (duplicate)
nitesh624’s picture

Assigned: nitesh624 » Unassigned

Unassigning issue from me as it closed