Open tecosaur opened 2 years ago
Thank you.
I agree with some of the downsides of the current approach, like the Symbol(...)
pattern which is too verbose. On the other hand, I'm not a big fan of having all the params as Vectors
, especially as in the majority of the cases it will be just one value.
Leaving it open for discussions to get more input before picking the v5 features.
The problem with the current behaviour
At the moment, form support is a bit messy. Repeating inputs with the same name causes the last value to overwrite all the others, unless the name ends with
[]
in which case a list of all provided values is formed — unless you're using a multipart form, in which case multiple values with[]
doesn't work at all.I assume the
[]
at the end convention is taken from PHP which does this, but I find it needlessly complicates the situation. Consider the following examples:foo=1&foo=2
foo[]=1&foo[]=2
foo[]=1&foo=2
foo=1&foo[]=2
foo=1&foo[]=2&foo=3
The first two have a semi-obvious behaviour, but beyond that, the situation … deteriorates.
It's also a bit annoying to write
Symbol("name[]")
instead of:name
when accepting multiple values.I think we can do better.
My proposal
I propose a breaking change for v5, to make form values be handled in a simpler, and more consistent manner.
Treat all form fields as multi-value, with no ifs, buts or ands
Consider the following example:
Depending on whether you put
[]
afterfoo
or not you'll either seeor
By treating all form fields as multi-value, you'd have the following result
This has a few advantages:
[]
in the name orSymbol("...[]")
payload[:name][end]