I really like Play 2.0’s form mapping system, but I had a question about how to implement forms with lists of similar controls.
In Rails, if I had a list of form parameters like
foo[]=3, bar[]=4, foo[]=2, bar[]=5
I’d get a structure that looks like
[{:foo => 3, :bar => 4}, {:foo => 2, :bar => 5}].
In Play, I can do this by specifying explicit indices, e.g.
foo[0]=3, foo[1]=4, etc.
But for forms where I can dynamically add and remove list entries on the page before submitting the form to the server, this requires a little bookkeeping to make sure the indices are right. Does Play support something like Rails’s approach, where I can add new foo/bar pairs to my forms and have each occurrence appear as a separate entry in an array?
The problem you have comes from the RepeatedMapping where the
indexesfunction in the companion is simply collecting the ints, sorting them and finally distinct…What could be done is to update the map to have indexes continuous…
So the only way, I can see so far at least, is to create the same kind of RepeatedMapping that will handle it… But I guess it could be added as a improvement of the functionality?