A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Tags / array input

collimarco
2018-09-08

It is very common to need a text input that allows multiple values (e.g. tag input).

This is not only useful for tags, but it is also very useful when you build a UI for JSON APIs that often make use of arrays.

Most languages and frameworks support arrays - HTML seems the only technology that doesn’t support them natively.

Currently the only alternatives are:

  • use libraries like https://select2.org
  • use multi line textareas and then split the string with newlines
Garbee
2018-09-13

You can also have an input with a defined delimiter (such as comma, semicolon, etc) to separate entries for exploding on the backend.

HTML doesn’t support dynamic ones natively because it is built for generating mostly static controls. Do to an array input “properly” you’d need to have to dynamically generate new input nodes in a consistent way and name pattern. It’s not impossible, but it is low-hanging fruit on the grander scheme of the HTML spec currently.

HTML does support a static length array input already. You simply provide the input options and name them with name="arrayname[]" and at least in the case of PHP (and most of web frameworks I see) they will instantly combine those entries into an array. So if you don’t need a dynamic number of entries, it’s already available.

Since the web platform already allows for both static and dynamic (with JS) array input options, it isn’t something the standards people are too interested in doing. As per the Extensible Web Manifesto they are looking more into new features that add capabilities that can’t be achieved or are extremely difficult and/or costly to do currently.

Your best path forward to get a new element for this made is to build your own. Make a web component that encapsulates your idea and can be used in production apps for experimentation. Once it has gained traction and you’ve worked some of the integration issues out that will exist, you then have better grounding to push to have it standardized and provided in user agents.

collimarco
2018-09-14

No. That is not what I mean. I think that HTML should offer a <input type="text" multiple>. We already have that for selects.

Garbee
2018-09-14

How would <input multiple> manifest visually? Select has multiple because you can select multiple things. Textfields and generic text input does not need it, because inherently by default you can input multiple things. It is up to the developer to decide how to explode that into an array if they chose to and convey how to provide proper input to the user.

Wanting new attribute still does not negate the extensible web manifesto or the suggestion to make a web component for this first. Battle test it in the field, get feedback, and have developers push for adopting it as a standard.

collimarco
2022-01-11

After some years, I’m working also on another project and I need this feature again… This confirms that this feature would be useful for many projects.

The database (PostgreSQL) supports the array type, the ORM supports the array type, the controllers support arrays, every language has an array type… and HTML does not have an array type. This is really inconvenient and strange: you need to use JS or use other hacks in your server side code, but that definitely doesn’t sound correct. The correct solution would be to have a string array as an HTML input.

HTML already has select multiple, so I don’t see a reason for not having that on input too.

I hope to see something like this in the future:

<input type="array">

Or:

<input type="tags">