bigskysoftware / htmx-extensions

102 stars 30 forks source link

Extension json-enc serializes only the last selected option of a select element when multiple is enabled #33

Open achinaou opened 1 month ago

achinaou commented 1 month ago

When using the extension json-enc with HTMX 2.0.0, the serialization of the selected options to JSON keeps only the last selected option.

Given this HTML:

<!DOCTYPE html>
<html>
   <head>
      <script src="https://unpkg.com/htmx.org@2.0.0"></script>
      <script src="https://unpkg.com/htmx-ext-json-enc@2.0.0/json-enc.js"></script>
   </head>
   <body>
      <form hx-ext="json-enc" hx-post="/json">
         <select id="fruits" name="fruits" multiple="multiple">
            <option value="apple" selected="selected">Apple</option>
            <option value="banana" selected="selected">Banana</option>
            <option value="cherry">Cherry</option>
         </select>
         <button type="submit">Submit</button>
      </form>
   </body>
</html>

The JSON payload will be this:

{
  "fruits": "banana"
}

What else I tested and worked as expected:

HTMX Version Serialization Method
1.9.12 default
1.9.12 json-enc
2.0.0 default

So, the issue only exists in the combination of HTMX 2.0.0 and the json-enc extension.

schungx commented 4 weeks ago

Same here. I've also raised an issue: https://github.com/bigskysoftware/htmx-extensions/issues/58