Support the '#multiple' attribute for the email element

Created on 15 July 2022, almost 2 years ago
Updated 15 June 2024, 3 days ago

Problem/Motivation

Email FAPI element was added without support of multiple attribute. See https://www.drupal.org/project/drupal/issues/1174620#comment-4564144 β†’ .

Currently even if the attribute set directly through #attributes property Drupal does not accept comma-separated emails.

Steps to reproduce

  • Add to any form an email element
$form['email'] = [
  '#type' => 'email',
  '#title' => $this>t('Email'),
];
 
  • Try to add a multiple attribute via the #attributes property
  •   '#attributes' => ['multiple' => '']
    
  • Fill in the email input element by several comma-separated emails. E.g. foo@example.com,bar@example.com
  • Submit the form.
  • Expected: the form must be submitted without errors
  • Actual: HTML5 doesn't return any errors but Drupal element validation does.
    The email address <em>foo@example.com,bar@example.com</em> is not valid. Use the format user@example.com.
  • Proposed resolution

    Support "multiple" attribute same way as for select lists.

    $form['emails'] = [
      '#type' => 'email',
      '#title' => $this->t('Emails'),
      '#multiple' => TRUE,
      '#description' => $this->t('Comma-separated email addresses.')
    ];
    
    • Allow to add multiple attribute via #multiple element property
    • Update element validation to support #multiple property

    Later, it will be possible to add this option to Email fields as well, but first, an element itself needs to comply with the HTML documentation.

    Remaining tasks

    Items in the MR
    #44
    #45
    Review
    Commit

    User interface changes

    NA

    API changes

    The API of the Email Render element must be updated.
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

    Data model changes

    NA

    Release notes snippet

    Provide multiple attribute support for Email render element.

    πŸ“Œ Task
    Status

    Needs review

    Version

    11.0 πŸ”₯

    Component
    FormΒ  β†’

    Last updated 26 minutes ago

    Created by

    πŸ‡·πŸ‡ΊRussia Chi

    Live updates comments and jobs are added and updated live.
    Sign in to follow issues

    Merge Requests

    Comments & Activities

    Not all content is available!

    It's likely this issue predates Contrib.social: some issue and comment data are missing.

    • First commit to issue fork.
    • last update 8 months ago
      30,402 pass, 4 fail
    • Status changed to Needs review 8 months ago
    • last update 8 months ago
      30,402 pass, 4 fail
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Pipeline finished with Failed
      8 months ago
      Total: 676s
      #34719
    • last update 8 months ago
      30,425 pass
    • last update 8 months ago
      30,425 pass
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Pipeline finished with Success
      8 months ago
      Total: 622s
      #35250
    • Status changed to Needs work 8 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Issue summary seems incomplete, I got it started but if TBD sections can be reviewed and if they don't apply can put NA. But seems like a UI or API change that should be noted.

      May need a change record but not 100% there.

    • Status changed to Needs review 8 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • last update 8 months ago
      30,427 pass
    • Pipeline finished with Success
      8 months ago
      Total: 598s
      #36795
    • Status changed to RTBC 8 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Rebased to run test-only feature

      1) Drupal\Tests\system\Functional\Form\EmailTest::testFormEmail
      Behat\Mink\Exception\ElementNotFoundException: Form field with id|name|label|value "email_multiple" not found.
      /builds/issue/drupal-3296190/vendor/behat/mink/src/WebAssert.php:662
      /builds/issue/drupal-3296190/core/tests/Drupal/Tests/UiHelperTrait.php:84
      /builds/issue/drupal-3296190/core/modules/system/tests/src/Functional/Form/EmailTest.php:36
      /builds/issue/drupal-3296190/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
      ERRORS!
      

      Which is good.

      Updated the change record some. Think it would be good to get in and then work on conversions in core but lets see.

      Rest looks good

    • last update 8 months ago
      30,437 pass
    • last update 8 months ago
      30,442 pass
    • last update 8 months ago
      30,464 pass
    • last update 8 months ago
      30,483 pass
    • last update 8 months ago
      30,485 pass
    • last update 8 months ago
      30,486 pass
    • Pipeline finished with Failed
      8 months ago
      Total: 715s
      #44594
    • last update 7 months ago
      30,488 pass
    • last update 7 months ago
      30,511 pass
    • Status changed to Needs work 7 months ago
    • πŸ‡ΊπŸ‡ΈUnited States xjm

      The issue summary includes both patches and multiple merge requests. There should be only one canonical patch or merge request listed.

      Please close any non-canonical merge request(s) and hide non-canonical patches. If you don't have permission to close merge requests, please hide any non-canonical patches and then document which merge request(s) should be closed in an issue comment and under a separate header in the issue summary. This will allow a committer to close them for you. Thanks!

    • πŸ‡ΊπŸ‡ΈUnited States xjm
    • Pipeline finished with Canceled
      7 months ago
      Total: 154s
      #48112
    • Pipeline finished with Failed
      7 months ago
      Total: 652s
      #48114
    • Status changed to Needs review 7 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Status changed to RTBC 7 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Seems like we already have hidden non-canonical patches.
      Updated PR from the 11.x branch and returned the previous status.

    • last update 7 months ago
      30,519 pass
    • last update 7 months ago
      30,530 pass
    • last update 7 months ago
      30,554 pass
    • last update 7 months ago
      30,602 pass
    • 31:29
      26:55
      Running
    • last update 7 months ago
      30,605 pass
    • last update 7 months ago
      30,667 pass
    • last update 7 months ago
      30,675 pass
    • last update 7 months ago
      Build Successful
    • last update 7 months ago
      30,684 pass
    • last update 7 months ago
      30,688 pass
    • last update 7 months ago
      30,688 pass
    • last update 7 months ago
      30,688 pass
    • last update 6 months ago
      30,697 pass
    • last update 6 months ago
      30,698 pass
    • last update 6 months ago
      30,712 pass
    • last update 6 months ago
      30,724 pass
    • last update 6 months ago
      30,764 pass
    • last update 6 months ago
      30,766 pass
    • last update 6 months ago
      25,901 pass, 1,799 fail
    • last update 6 months ago
      25,931 pass, 1,808 fail
    • last update 6 months ago
      25,886 pass, 1,859 fail
    • last update 6 months ago
      25,924 pass, 1,811 fail
    • last update 6 months ago
      25,923 pass, 1,831 fail
    • last update 6 months ago
      25,892 pass, 1,841 fail
    • last update 6 months ago
      25,888 pass, 1,829 fail
    • last update 6 months ago
      25,945 pass, 1,835 fail
    • last update 5 months ago
      25,960 pass, 1,838 fail
    • last update 5 months ago
      25,998 pass, 1,805 fail
    • Status changed to Needs work 5 months ago
    • πŸ‡¬πŸ‡§United Kingdom longwave UK

      Added some questions/feedback to the MR.

    • Pipeline finished with Failed
      5 months ago
      Total: 163s
      #76956
    • Pipeline finished with Success
      5 months ago
      #76960
    • Status changed to Needs review 5 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Fixed two issues from the comments.

    • Status changed to RTBC 5 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Seems additional feedback has been addressed.

    • Status changed to Needs work 5 months ago
    • πŸ‡¬πŸ‡§United Kingdom longwave UK

      Sorry, one more little bit of feedback: we should add docs so users know this is possible.

    • Pipeline finished with Failed
      5 months ago
      #83030
    • Pipeline finished with Failed
      5 months ago
      Total: 1481s
      #83051
    • Status changed to RTBC 5 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Updated the element doc and info.

      Since the last changes don't have any effect on the element behavior I switch back the RTBC status.

      P.S. Ignore the spell-checking error. "Argument list too long" is a Drupal core issue - πŸ› Spell-checking job fails with "Argument list too long" when too many files are changed Active .
      Seems like the last merging of the 11.x caused the error.

    • Status changed to Needs work 5 months ago
    • πŸ‡¬πŸ‡§United Kingdom longwave UK

      Added a few more nits and questions to the MR.

    • Pipeline finished with Canceled
      5 months ago
      Total: 80s
      #84214
    • Pipeline finished with Failed
      5 months ago
      Total: 173s
      #84215
    • Pipeline finished with Success
      5 months ago
      Total: 584s
      #84220
    • Status changed to Needs review 5 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      @longwave I went over your last comments.

    • Status changed to Needs work 5 months ago
    • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

      This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

      Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

    • πŸ‡¬πŸ‡§United Kingdom longwave UK

      Responded to the MR comments.

    • Pipeline finished with Success
      5 months ago
      Total: 756s
      #87120
    • Pipeline finished with Success
      5 months ago
      Total: 615s
      #87125
    • Status changed to Needs review 5 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Handled the last issues.
      One of them was a really important one, @longwave nice catch!

    • Status changed to RTBC 4 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Appears feedback has been addressed.

    • Status changed to Needs work 4 months ago
    • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

      I'm triaging RTBC issues β†’ . I read the IS and the comments. I didn't find any unanswered questions.

      I read the MR and left some suggestions. I also think input is needed from Usability on the new strings. Adding tag for a usability review.

      I read the MR and I do suggest a change. When I read "Provide #multiple property for email render element with correct validation." I ask myself why we would provide an element with incorrect validation. I think it could be reworded. I know it is minor.

      Setting to NW.

    • Pipeline finished with Success
      4 months ago
      #103425
    • Status changed to Needs review 4 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      @quietone I went through your proposals in MR.
      Some of them I've fixed and for some of them I wrote an answer. You can recheck them.

    • Status changed to Needs work 3 months ago
    • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

      This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

      Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

    • Pipeline finished with Success
      3 months ago
      Total: 614s
      #131753
    • Status changed to Needs review 3 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Status changed to Needs work 3 months ago
    • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

      This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

      Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

    • Pipeline finished with Success
      2 months ago
      Total: 736s
      #140640
    • Status changed to Needs review 2 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Status changed to Needs work 2 months ago
    • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

      Usability review

      We discussed this issue at πŸ“Œ Drupal Usability Meeting 2024-04-19 Needs work . That issue will have a link to a recording of the meeting.

      For the record, the attendees at the usability meeting were @AaronMcHale, @benjifisher, @rkoller, @shaal, @simohell, @skaught, and @worldlinemine.

      If you want more feedback from the usability team, a good way to reach out is in the #ux channel in Slack.

      There was some discussion about whether we should handle multiple email addresses in separate textfields instead of allowing a comma-separated list. We decided that the current approach is the right choice. It is consistent with the email specification, and the Field API (not the Form API) is the right place to handle multiple textfields.

      We tested various invalid entries, and we used the Disable HTML5 validation β†’ module so that we could see the error messages provided by this issue. The current approach works well, but we would like to make two changes:

      1. Do not treat empty emails differently from other invalid emails.
      2. Insert a comma in the second sentence: "Use the format user@example.com, and separate the addresses with a comma."

      An error message should do two things: describe the error state and give information on how to fix it. The current message, "All email addresses must be non-empty.", tries to do both at once. We think it would be clearer to use the same format as the other error messages:

      The email address "" is not valid. Use the format user@example.com, and separate the addresses with a comma.

      If possible, use the un-trimmed value in the error message so that there is a distinction between ,, and , ,.

      Other argument in favor of (1):

      • The error messages are more consistent.
      • If a user enters an empt address and an invalid one, then currently they get the message about an empty address. They fix it and try again, and get the message about the invalid address. Let's list all the errors at once.

      The second point is purely grammatical: when combining independent clauses with "and", there should be a comma after the first one.

    • Pipeline finished with Failed
      about 2 months ago
      Total: 991s
      #153227
    • Pipeline finished with Canceled
      about 2 months ago
      Total: 1399s
      #153263
    • Pipeline finished with Success
      about 2 months ago
      Total: 994s
      #153283
    • Status changed to Needs review about 2 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Hi @benjifisher
      1. Fixed a small grammatic issue
      2. About the empty email error message:

      If a user enters an empt address and an invalid one, then currently they get the message about an empty address. They fix it and try again, and get the message about the invalid address. Let's list all the errors at once.

      I really liked this idea and implemented it.
      But I don't like the idea to make an "empty" message like this

      The email address "" is not valid. Use the format user@example.com, and separate the addresses with a comma.

      For me, this message is unclear/unreadable/not user-friendly. It is very difficult to correctly display an "empty" value. Using quotation marks for this purpose can only worsen the situation, as the user may start looking for something that is not there. A message like that really can confuse a user.
      While the direct text that an empty email address value has been entered is clear and not ambiguous.

    • Status changed to Needs work about 2 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Made the small change to the CR mentioned.

      Appears to be 1 open thread but overall looking good! Believe this one to be very close.

    • Status changed to Needs review about 2 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Wrote an answer to the last comment in the MR

    • Status changed to Needs work about 2 months ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Not sure if it saved but don't see the comment?

    • Pipeline finished with Success
      about 2 months ago
      Total: 757s
      #159701
    • Status changed to Needs review about 2 months ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Sorry @smustgrave, forgot to submit my comment there :)

    • Status changed to RTBC about 1 month ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      @HitchShock no worries figured that was probably the case. All threads have been addressed/answered so believe this one to be good.

    • πŸ‡©πŸ‡ͺGermany rkoller NΓΌrnberg, Germany

      What is the error message now when there are two or more commas in a row? That scenario was the reason behind the suggestion @skaught raised. By removing extra commas the message wouldn't been necessary anymore. Without the stripping it is necessary.

    • πŸ‡©πŸ‡ͺGermany rkoller NΓΌrnberg, Germany

      one other detail, at first i thought it is unrelated to this issue but it seems it is. in the ux meeting as well as testing for myself, after applying the patch, i've added '#multiple' => TRUE, line to the email field in SiteinformationForm.php. Problem is as soon as the multiple line is added the email field is shown empty on page reload and or save (in Safari 17.4.1 in Sonoma 14.4.1). At the same time I am able to see the content of the field when i open the page in for example Firefox. As soon as i remove the multiple equals true line the emails become visible again in Safari as well.

    • Status changed to Needs work 30 days ago
    • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

      Thanks for working on this one, left some comments on the MR

    • Pipeline finished with Success
      24 days ago
      Total: 562s
      #182046
    • Status changed to Needs review 24 days ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      Solved the last PR issues

    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      smustgrave β†’ changed the visibility of the branch 11.x to hidden.

    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      smustgrave β†’ changed the visibility of the branch 3296190-support-multiple-attribute to hidden.

    • Status changed to RTBC 12 days ago
    • πŸ‡ΊπŸ‡ΈUnited States smustgrave

      Re-ran test-only feature

      1) Drupal\Tests\system\Functional\Form\FormTest::testDisabledElements
      TypeError: Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault(): Argument #1 ($values) must be of type array, null given, called in /builds/issue/drupal-3296190/core/modules/system/tests/src/Functional/Form/FormTest.php on line 790
      /builds/issue/drupal-3296190/core/modules/system/tests/src/Functional/Form/FormTest.php:799
      /builds/issue/drupal-3296190/core/modules/system/tests/src/Functional/Form/FormTest.php:790
      ERRORS!
      Tests: 16, Assertions: 622, Errors: 1.
      

      So change has coverage

      Believe all feedback has been addressed and code change seem fine to me.
      I followed the steps in the summary and manually can confirm this works as advertised.

    • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

      Thanks for the continued work on this issue.

      I reviewed the MR an the comments in the MR. I have left several suggestions for comment and code changes. Also, #44 and #45 need to be addressed. This is making changes to the UI and there should be a screenshot to show the changes. In particular, it would help to see the error messages in regard to the testing done in #44 and #45.

      I now see that I have erred by missing the usability review in #37. I will take a wee break and then read that and make any adjustments needed to my comments. I will leave at RTBC until I do that.

    • Status changed to Needs work 4 days ago
    • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

      There is still a question about the error message change suggested in #37 and disagreed with in #38. It is the same text I have questioned as well. I suggest the solution is to ask in #usability for more guidance.

    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

      I see that the simpler the work, the more it is scrutinized, and everyone sees something different and changes the same thing several times. And they pick on such trifles that are absolutely not critical and will not affect the overall functionality.
      Instead of quickly implementing a simple change, everyone is engaged in bureaucratic ping-pong for no real reason.

      In a month, someone else will come and say that they don't like some error text (which is generally displayed only when UI validation is disabled, which is almost never) or comment text.

      I'm tired of fulfilling the whims of everyone who comes to check the task. So I'm stopping working on the issue.

    • Status changed to Needs review 3 days ago
    • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
    • Pipeline finished with Success
      3 days ago
      Total: 675s
      #199688
    Production build 0.69.0 2024