[Enhancement] Proper handling of <input type="email" multiple />

I’m proposing an enhancement per the contribution guidelines, and looking to find out whether this patch might be accepted.

HTML5 added the “multiple” attribute to fields. This is useful as it means the user agent can perform email validation and strip whitespace.

However, the actual emails are submitted to the server as a comma-separated string.

Additionally, Rails magic turns something like

<%= f.email_field :emails, multiple: true %>

``

into

``

When submitted, we actually receive this:

params[:emails][0] = “foo,bar”

``

But we actually want this:

params[:emails] = [“foo”, “bar”]

``

I’m proposing a patch to handle some or all of this unusual (but standards based) behaviour.

When rendering an :email_field with the multiple property:

  • When the ActiveModel attribute is an Array, the value should be joined into a string separated by commas.
  • Alternatively, the value should be absent, and a should be added to the output
  • Don’t append to the name, so the form value remains a string rather than an array of strings
  • Append a hidden form input to indicate the Rails should interpret that form value as a comma-separated string, and turn it into an array

I think your proposal looks good. It’d be nice for us to support this feature.

Please submit a PR and ping me on GitHub so I can take a look.

Thank you,

Prem