Serialize multi-select values as an array #101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I have a multi-select in one of my forms. I started using Backbone.Syphon to serialize that form and I realized that it wasn't returning the values I am expecting. Before this change, it's returning the values of a multi-select as a nested array:
When submitting this format of serialized data to my backend (using Rails) via AJAX, the URL encoded value will be
foo%5B0%5D%5B%5D=bar1&foo%5B0%5D%5B%5D=bar2
. That looks weird and that's not what I am expecting.My expected output is:
Which will be
foo%5B%5D=bar1&foo%5B%5D=bar2
when URL encoded.Regarding the fix found in this pull request, I updated the
assignKeyValue
method to push each value into the array instead of pushing the array into an array to avoid the nested array output. I also added a spec for that and hopefully that helps in explaining my case further. All tests are still passing with these changes.If I'm still missing something or if I need to change something else, please let me know. :)
Thanks,
Patrick