htmx icon indicating copy to clipboard operation
htmx copied to clipboard

hx-val array handling

Open mlthlschr opened this issue 3 years ago • 3 comments

Currently, if I try to add an object containing an array on the first level to hx-val, the value is discarded and not added to the parameters of the call.

Example:

{
  "firstLevel": [1,2,3],
  "secondLevel": {
    "values": [4,5,6]
  }
}

Here, it fails due to the firstLevel field ("Multiple values for one key: "firstLevel"")) The secondLevel field would be accepted, as the whole objects gets passed as JSON.

Maybe arrays could be interpreted the same way as objects are.

mlthlschr avatar Jul 10 '22 17:07 mlthlschr

I know this is old but I ran into a similar problem so I thought I would post my solution here for future people. You could make this work by putting hx-vals into a js object: https://htmx.org/attributes/hx-vals/

jaxlo avatar Apr 19 '23 20:04 jaxlo