Support multiple attribute for email element Drupal 10

Created on 30 October 2023, 8 months 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

    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

    Closed: duplicate

    Version

    10.2 ✨

    Component
    FormΒ  β†’

    Last updated 1 day ago

    Created by

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

    Comments & Activities

    Production build 0.69.0 2024