Preserves the order of inserted field values#41
Conversation
When a form includes multiple fields with the same name (and thus multiple values for that field), we were inserting them with `Map.insertWith (<>)`. The order of arguments to `Map.insertWith` is the new value first, followed by the old value, so we were building the list in reverse order while merging. This corrects to building the list using the same order as in the request, and includes a simple test to verify.
|
I'm curious as to why the order matters, and if maybe we should have functions that don't care about the order and ones that do with appropriate names. |
|
So is I think this is a good change, curious what caused you to notice it or if it was causing issues somewhere |
|
To answer both questions, I noticed it and am attempting to fix it because I was playing around with this HTMX/Sortable.js widget. The order matters to preserve the user's sorting of elements.
As far as having separate functions, I wouldn't be opposed to it, but I would assume that either a user would want the order preserved or wouldn't care, at which point we might as well preserve the order since |
|
I think using flip is just fine here. Our main aversion to flip is using it when we control the functions and can easily swap the order of parameters, instead of using an unnecessary flip.
|
When a form includes multiple fields with the same name (and thus multiple values for that field), we were inserting them with
Map.insertWith (<>). The order of arguments toMap.insertWithis the new value first, followed by the old value, so we were building the list in reverse order while merging. This corrects to building the list using the same order as in the request, and includes a simple test to verify.