What's the name of the format/DSL utilized on the name attribute of HTML input elements?

What’s the name of the format/DSL utilized on the name attribute of HTML input elements?

So the shape of the values submitted by a .form are described by the name attribute in the inputs that are within that form, for example:

<input name="schema[categories][multiselect][2][id]" value="..."/>

So the server will transform this into an elixir struct that has a shape according to this name value.

What’s the name of this formatting? Where can I find more documentation about it?

Plug.Conn.Query has functions for dealing with that:

https://hexdocs.pm/plug/Plug.Conn.Query.html

Also interested to know if there’s any formal name for it. The field names are constructed by the inputs_for / form_for / input functions themselves

1 Like

Not sure if there’s a name for them, but they’re either 1:1 or inspired heavily from what Rails does with its params

1 Like

Yes, but if you want to make your own inputs then it is good to know the specification for the names, which isn’t documented anywhere.

The closest documentation seems to be the shapes displayed in this ecto guide. In short, each [value] in a name string represents a key in a map, to make a “list” you would make a map of numbered keys, basically using values like [1] for the given input’s name.

That‘s just using a common convention around url encoding: Plug.Conn.Query — Plug v1.15.2

that looks different from using a map with integer keys to represent lists when submitting to a changeset, form helpers don’t make use of foo[]=bar&foo[]=baz like Plug.Conn.Query shows

That notation doesn‘t work for a “list of maps”. You cannot do form[][id]=1&form[][value]=something&form[][id]=2&form[][value]=somethingelse and have that decoded to a list of maps. That‘s why things are encoded using indexes as key per individual map.

1 Like