Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301158

Support the '#multiple' attribute for the email element

$
0
0

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

    Confirm there are no implications here for things like \Drupal\Core\Field\Plugin\Field\FieldFormatter\MailToFormatter that expect a single email address.
    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.


    Viewing all articles
    Browse latest Browse all 301158

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>