Problem/Motivation

Hi,

We had an accessibility audit and one of the issues was that the error message for email fields was not helpful enough and should contain something about the format it expects. Personally I disagree and think the message is good enough, but perhaps it is worth to look into.

I decided to create a patch instead of overriding the email class because the latter would not keep track of any possible future changes to the Email field.

Sincerely,

Dagomar

Proposed resolution

The current email field validation error message doesn't contain anything about the email format, So add a sample format in the error message
Current error message
"The email address abc.@in is not valid."
current error message
Proposed error message
"The email address abc.@in is not valid. Use the format user@example.com."
proposed error message

Comments

dagomar created an issue. See original summary.

dagomar’s picture

StatusFileSize
new750 bytes
idebr’s picture

Title: Email field validation error accessibility issue. » Improve Email field validation error message to improve accessibility
Component: render system » field system
Category: Bug report » Task
Status: Active » Needs review
joachim’s picture

One problem with this is that email addresses can be more complex than that.

For instance, you can have 'user+suffix@example.com'.

Version: 8.8.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. 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.

abhijith s’s picture

StatusFileSize
new5.18 KB
new6.87 KB

Applied patch #2 on 8.9.x and it works fine.

Before patch:
before

After patch:

after

RTBC +1

gauravvvv’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs usability review
StatusFileSize
new31.01 KB
new24.44 KB

Patch #2, works fine to me. Moving to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/Email.php
@@ -76,7 +76,7 @@ public static function validateEmail(&$element, FormStateInterface $form_state,
 
     if ($value !== '' && !\Drupal::service('email.validator')->isValid($value)) {
-      $form_state->setError($element, t('The email address %mail is not valid.', ['%mail' => $value]));
+      $form_state->setError($element, t('The email address %mail is not valid. It should look like example@domain.com.', ['%mail' => $value]));
     }
   }

Instead of 'it should look like example@domain.com' could we use something like 'use the format user@example.com'.

Also normally with examples we use example.com which is reserved. domain.com is an actual valid domain that points to a website - so we shouldn't use that.

richa_porwal’s picture

Assigned: Unassigned » richa_porwal
richa_porwal’s picture

Hi Team,

I have created patch for the above problem motivation. Need review

richa_porwal’s picture

Assigned: richa_porwal » Unassigned
richa_porwal’s picture

Status: Needs work » Needs review

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

Manibharathi E R’s picture

StatusFileSize
new54.46 KB
new60.87 KB

Applied patch #2 on 9.4.3 and it works fine.

Before Patch Apply

before-patch

After Patch Apply

after-patch

gaurav-mathur’s picture

Version: 9.4.x-dev » 10.1.x-dev
StatusFileSize
new23.68 KB
new45.42 KB

patch #10 successfully applied on drupal 10.1.0-dev and 9.4.x Which I showed by screenshot.

Thanks and Regards .

prasanth_kp’s picture

StatusFileSize
new10.71 KB
new13.95 KB

#10 Patch Applied on 10.1.x-dev and it works fine for me.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Even though this is a task think it could use test coverage for the change.

ranjith_kumar_k_u’s picture

StatusFileSize
new956 bytes
new808 bytes
new1.65 KB

Added tests, please review

ranjith_kumar_k_u’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs issue summary update

Tests look good

This could use an issue summary though for what the message was updated to and why. Current IS mentions accessibility issue but how does this now pass?

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.

yoroy’s picture

This is ok to add, but minor indeed. No need for an explicit usability review & signoff. Go for it!

ranjith_kumar_k_u’s picture

Issue summary: View changes
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

In that case the change looks good and appears correctly.

  • quietone committed ba576b5e on 11.x
    Issue #3114016 by ranjith_kumar_k_u, richa_porwal, dagomar, Gauravvvv,...
quietone’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/modules/field/tests/src/Functional/Email/EmailFieldTest.php
@@ -112,6 +112,15 @@ public function testEmailField() {
+    $value = 'abc.@in';

I'd rather this use 'foo' instead of 'abc' but it has not thrown any spelling errors.

Thanks everyone! Our UI is a wee bit better.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.