Fix #119: Fix constructing more complex object with arrays#126
Fix #119: Fix constructing more complex object with arrays#126Telroshan merged 2 commits intobigskysoftware:mainfrom
Conversation
…revent duplicating arrays elements in final object
✅ Deploy Preview for htmx-extensions canceled.
|
|
Hey, thanks for your work @meex28 ! Hence why I took the liberty to simplify your code to reduce the diff compared to the previous code, I hope you understand! Thanks again for your work & patience! |
Fixing the bug #119
Description
Fixed incorrect array handling when combining complex hx-vals with json-enc. Previously, when processing:
<button hx-ext="json-enc" hx-vals='{"Id":1,"Items":["abc","xyz"]}'> ...</button>The
encodeParametersfunction gets as input FormData object like:When retrieving types from hx-vals, for each entry with an
Itemskey, whole array was added to the result object:Instead of:
To change this behaviour, the function now first groups FormData parameters by keys, and then maps raw values to types from hx-vals.
Testing
In the test
handles hx-vals properlyadded an array-type value ('array': ['text', 123, {'key': 'value'}]) and expects it to to be properly included in the body.Checklist
npm run test) and verified that it succeeded