Tags / array input


#1

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

#2

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.


#3

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


#4

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.