Problem/Motivation

The error message if the start is before the end date is unnecessary technically and should be changed. Also the link text in for the Inline Form Error summary needs editing.

Proposed resolution

Change the interface text from "The [field label] end date cannot be before the start date" to "The end of [field name] cannot be before its start." (After the patch, the field name is in italics and there is ending punctuation.)

Remaining tasks

  • Link to related issues. Create them if needed. See #33.

User interface changes

Without the patch, without Inline Form Errors module

before patch, no Inline Form Errors

Without the patch, with Inline Form Errors module

before patch, with Inline Form Errors

With the patch, without Inline Form Errors module

after patch, no Inline Form Errors

With the patch, with Inline Form Errors module

after patch, with Inline Form Errors

API changes

None

Data model changes

None

Issue fork drupal-2895055

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ifrik created an issue. See original summary.

ifrik’s picture

Issue summary: View changes
ifrik’s picture

I'm working on this now.

ifrik’s picture

Status: Active » Needs review
StatusFileSize
new987 bytes

I've edited the error message and added some formatting to separate the field label from the rest of the message. However the "value 1" comes from the general widget base, and I make a different issue to change it in general.

ifrik’s picture

Status: Needs review » Needs work

Forgot to remove the devel code

ifrik’s picture

Status: Needs work » Needs review
StatusFileSize
new961 bytes

The last submitted patch, 4: 2895055-date-range-error-message-4.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: 2895055-date-range-error-message-6.patch, failed testing. View results

mpdonadio’s picture

Thanks. I think I like that error message better. Once you fix the fail, can you post an after screenshot to the IS? It will help with final review.

+++ b/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php
@@ -136,7 +136,7 @@ public function validateStartEnd(array &$element, FormStateInterface $form_state
-          $form_state->setError($element, $this->t('The @title end date cannot be before the start date', ['@title' => $element['#title']]));
+          $form_state->setError($element, $this->t('The end of <em>@title</em> cannot be before its start.', ['@title' => $element['#title']]));

Most of core uses %title as the placeholder in error messafes, which will add the <em> element. That will also make it easier to translate.

And just as a general note, even though this is a bug, the string change means it can't go against 8.3.x (since this is still an experimental, a committer may decide otherwise).

ifrik’s picture

Status: Needs work » Needs review
Issue tags: +DrupalBCDays, +String change in 8.4.0
StatusFileSize
new3.67 KB
new2.38 KB
new2.38 KB

Thanks for the review. I fixed the test and @.

The error message reads as:

The field title is rendered as "field label (value x)" by the field widget, so to turn that into something that is nicer to read would require a more far reaching change there, so I leave that as it is.

Status: Needs review » Needs work

The last submitted patch, 10: 2895055-date-range-error-message-10.patch, failed testing. View results

ifrik’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB
new39.3 KB

Uploading the patch, even though it will fail:

Locally, the test passes if I use @title, but when I replace it by %title it fails on line 1307 in the DateRangeFieldTest.

Status: Needs review » Needs work

The last submitted patch, 12: 2895055-date-range-error-message-12.patch, failed testing. View results

mpdonadio’s picture

#12, for the purpose of the test, I would be OK using @title. The main thing we are testing is the actual test and the error message.

See the comment on https://www.drupal.org/node/2863444#comment-12174307. I'm wondering if we need to split out the error messages to handle the case of same date, but end time < start time.

ifrik’s picture

Thanks, I'll change the test accordingly.

I tried to got around talking about date when the error would be caused the end time, by just using "end" and "start" in the error message. So I suppose one error message should be fine.

ifrik’s picture

The test now uses @title, but I'm still intrigued why it otherwise fails...

ifrik’s picture

Status: Needs work » Needs review
ifrik’s picture

Learning PHPUnit tests just to change an error message :-)

Test failed because assertText strips the HTML, while assertRaw keeps it.

mpdonadio’s picture

Issue tags: +Needs UX review

I'm good with this, but think a UX signoff is best here.

UX reviewer, is current message good or do we need to be more granular about the date/time portions in the error message? The current screenshots show date-only field, but this field can also capture date+time as two separate inputs.

Will try to post before/after screenshots of date+time tonight.

ifrik’s picture

Title: Edit the date range error message » Edit the date range error messages
Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new4.05 KB
new3.85 KB

I've added two other error messages to be fixed as well.

ifrik’s picture

I would change the wording make sure that users know that the format is invalid, not the date or time itself. And also name it without specifically saying that the date is the problem, because it could also be the format of the time that invalid.

What do you think of a text such as this - before I fix all the tests?
The format used for <em>End date</em> is invalid. Please change it to <em>2017-07-22 18:47:11</em>.

ifrik’s picture

Issue summary: View changes
Status: Needs work » Needs review

The error message about invalide date format, is not from the datetime_range module but from Drupal's core library, so I remove it again from the issue summary, to avoid any issue creep.

ifrik’s picture

Issue summary: View changes

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

xjm’s picture

Issue tags: -, -needs UX review +Needs usability review

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

benjifisher’s picture

Issue summary: View changes
StatusFileSize
new70.05 KB
new42.28 KB
new44.94 KB
new75.72 KB

I am updating the issue description. The original had only one screenshot, which is now out of date. The description did not mention that the screenshot was made with the inline_form_errors module enabled. I am attaching before and after screenshots with and without that module.

benjifisher’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs usability review +Needs followup

Usability review

We discussed this issue at #3176758: Drupal Usability Meeting 2020-10-20.

We agree that the text change is a step in the right direction. While testing the patch, we noticed a few more things that should be improved:

  1. When the Inline Form Errors module is enabled, the same message appears three times. Once is enough. The problem is deciding which one to keep.
  2. When the Inline Form Errors module is enabled, we do not need the field label in the message. It could be simply "The End date cannot be before the Start date" (using the labels of the subfields) or "The end cannot be before the start."

We should not try to Fix Everything as part of this issue, but before this issue is fixed we should either create new issues or find existing ones. Either way, add them as related issues here. (If there is an easy way to do (2), then that could be added to this issue.) As far as testing and code review are concerned, this issue is RTBC, but I am setting the status to NW for the related issues.

aaronmchale’s picture

I agree with @benjifisher in #33, this is a small patch which improves existing messaging, once follow-ups are created/found I'm happy with this being RTBC.

Thanks,
-Aaron

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

YazanMajadba made their first commit to this issue’s fork.

yazanmajadba’s picture

StatusFileSize
new995 bytes

In sometimes the error messages are appear duplicate
This patch solve this issue, show error message only in end date field

yazanmajadba’s picture

StatusFileSize
new975 bytes

In sometimes the error messages are appear duplicate
This patch solve this issue, show error message only in end date field

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.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.

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.